This server exchanges a Snapchat OAuth authorization code for a Firebase custom token so the React app can sign in with signInWithCustomToken.
- Copy
.env.exampleto.env. - In the Snapchat Developer Portal, create an app. For this server-side flow use the Confidential OAuth 2.0 Client ID and its Client Secret. Under Login Kit, add a redirect URI:
- Dev:
http://localhost:5173/auth/snapchat/callback - Production:
https://your-domain.com/auth/snapchat/callback
- Dev:
- In
.env, setSNAPCHAT_CLIENT_ID(use the Confidential OAuth 2.0 Client ID from the portal) andSNAPCHAT_CLIENT_SECRET. - For Firebase Admin, either:
- Set
FIREBASE_SERVICE_ACCOUNT_PATHto the path to your service account JSON (e.g../serviceAccountKey.json), or - Set
GOOGLE_APPLICATION_CREDENTIALSto that path and leaveFIREBASE_SERVICE_ACCOUNT_PATHunset.
- Set
pnpm install
pnpm run build
pnpm startFor development with auto-restart:
pnpm run devServer listens on http://localhost:4000 by default. The React example uses VITE_CUSTOM_AUTH_SERVER_URL=http://localhost:4000 (default) so the Snapchat button and callback can reach it.
GET /auth/snapchat/config– returnsclientId,authUrl, andscopesfor the client to start the OAuth redirect.POST /auth/snapchat/token– body{ code, redirect_uri }; exchanges with Snapchat, fetches user id, mints a Firebase custom token; returns{ customToken }.