···11+import {
22+ configureOAuth,
33+ createAuthorizationUrl,
44+ resolveFromIdentity
55+} from '@atcute/oauth-browser-client';
66+77+async function initializeSession() {
88+ configureOAuth({
99+ metadata: {
1010+ client_id: 'http://127.0.0.1/client-metadata.json',
1111+ redirect_uri: 'https://example.com/oauth/callback'
1212+ }
1313+ });
1414+1515+ const { identity, metadata } = await resolveFromIdentity('mary.my.id');
1616+1717+ const authUrl = await createAuthorizationUrl({
1818+ metadata: metadata,
1919+ identity: identity,
2020+ scope: 'atproto transition:generic transition:chat.bsky'
2121+ });
2222+2323+ await sleep(200);
2424+2525+ // redirect the user to sign in and authorize the app
2626+ window.location.assign(authUrl);
2727+2828+ // if this is on an async function, ideally the function should never ever resolve.
2929+ // the only way it should resolve at this point is if the user aborted the authorization
3030+ // by returning back to this page (thanks to back-forward page caching)
3131+ await new Promise((_resolve, reject) => {
3232+ const listener = () => {
3333+ reject(new Error(`user aborted the login request`));
3434+ };
3535+3636+ window.addEventListener('pageshow', listener, { once: true });
3737+ });
3838+}