finishSignIn
uses location
If the page was opened coming back from signing in (its fragment holds the answer), finish signing in, tell the registry, and go back to the page it started from. Throws what went wrong, if it didn't work.
import { COMING_BACK, comingBack, configure, SIGNED_IN, signedInHere } from "#codebase/tcmts/registry/session"; import { finalizeAuthorization } from "@atcute/oauth-browser-client"; export async function finishSignIn(): Promise<boolean> { const params = new URLSearchParams(location.hash.slice(1)); if (!params.has("state") || !(params.has("code") || params.has("error"))) return false; // (so it isn't used twice) history.replaceState(null, "", location.pathname + location.search); await configure(); const { session } = await finalizeAuthorization(params); localStorage.setItem(SIGNED_IN, session.info.sub); await signedInHere(session.info.sub); const back = comingBack(sessionStorage.getItem(COMING_BACK), location.pathname); sessionStorage.removeItem(COMING_BACK); location.replace(back); return true; }
uses
- tcmts.registry.session.COMING_BACK
- tcmts.registry.session.SIGNED_IN
- tcmts.registry.session.comingBack
- tcmts.registry.session.configure
- tcmts.registry.session.signedInHere