Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I know my 'auth' and 'p256dh' keys. #715

Open
x9nico opened this issue May 25, 2022 · 1 comment
Open

How can I know my 'auth' and 'p256dh' keys. #715

x9nico opened this issue May 25, 2022 · 1 comment

Comments

@x9nico
Copy link

x9nico commented May 25, 2022

Hello, I'm not understanding how can I know my auth and p256dh keys. Any ideas?

@kosso
Copy link

kosso commented Aug 18, 2022

This information is returned by subscribe() after a user Allows Notifications.

async function subscribe() {
    let sw = await navigator.serviceWorker.ready;
    console.log('ServiceWorker', sw);
    let subscription = await sw.pushManager.subscribe({
        userVisibleOnly: true,
        // applicationServerKey is obtained from a server-side call to web-push `generateVAPIDKeys()`
        applicationServerKey: '<PUBLIC_VAPID_KEY>' 
    });

    // Be sure to JSON.stringify the result, or you won't see the keys in the console.
    
    console.log(JSON.stringify(subscription));
    // store this in a database etc. for you to be able to send messages to the user. later
    
    // For testing, I add it to the web page for copy/paste testing purposes on the sever side, since the console will ellipsify/shorten the long endpoint URL
    const p = document.createElement("p");
    p.appendChild(document.createTextNode(JSON.stringify(subscription)));
    document.querySelector("html").appendChild(p);

}
            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants