Hosted GitHub sign-in
client.oauth signs Sandbox customers in through Modem’s GitHub OAuth integration. It is separate from signing in to the Modem app and from your own authentication server.
Configure the return origin
Use a Sandbox project. Add your deployed HTTPS origin to the project’s Sign-in return origins. Loopback hosts, including localhost, 127.0.0.1, [::1] and *.localhost, are allowed for local development. The callback must return to an allowed origin; arbitrary HTTP websites are not accepted.
Start sign-in
const returnTo = new URL('/sign-in/callback', window.location.origin).href
const url = await client.oauth.authorizationUrl('github', { returnTo })
window.location.assign(url)The SDK creates a PKCE verifier and state and stores them in this tab’s sessionStorage. Start and finish in the same tab. Starting another sign-in for the same project replaces its pending state. Browser storage and Web Crypto must be available.
Finish the callback
import { OAuthSignInError } from '@preternatural-js/client-sdk'
try {
const result = await client.oauth.completeSignIn()
if (result) {
// The client now holds result.session.
window.history.replaceState({}, '', '/signed-in')
}
} catch (error) {
if (error instanceof OAuthSignInError) {
showSignInFailure(error.reason)
} else {
throw error
}
}completeSignIn(pageUrl?) returns null when the URL has no sign-in result. Otherwise it consumes pending state, checks the returned state, exchanges the one-time code and adopts the session. Configure a session store to keep it after a reload. Remove callback parameters after handling them.
A state_mismatch means this tab has no matching pending flow. Start a new sign-in instead of ignoring the check. Provider refusal or a failed code exchange also requires a fresh attempt; do not reuse a consumed code. Do not log callback codes, tokens or PKCE verifiers.