This repository was archived by the owner on May 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
45 lines (43 loc) · 1.81 KB
/
Copy pathauth.ts
File metadata and controls
45 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// NextAuth v5 (Auth.js) — GitHub OAuth
// Run `bun add next-auth@beta` already done.
// Env: AUTH_SECRET, AUTH_GITHUB_ID, AUTH_GITHUB_SECRET (set in .env.local)
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
// Plain provider config — Auth.js derives `redirect_uri` from the
// incoming request's host, which on production is always
// tokmato.nihildigit.dev and matches what the GitHub OAuth App
// has registered. The earlier `redirectProxyUrl` shim was added
// for hypothetical preview-deploy access, but in practice the
// *.vercel.app preview URLs are gated behind Vercel SSO and never
// serve OAuth traffic; the proxy round-trip just added an extra
// state-cookie hop that the Capacitor WebView fumbled, breaking
// sign-in in the APK with InvalidCheck on every callback.
GitHub,
],
trustHost: true,
// For MVP: single user, JWT session. Add Vercel KV adapter later if multi-device.
session: { strategy: "jwt" },
pages: {
// Use shadcn-styled custom sign-in page later. For now, default.
},
callbacks: {
async jwt({ token, account }) {
// Bind token.sub to the OAuth provider's stable account id on first
// sign-in. Without this, JWT strategy + no DB adapter mints a fresh
// UUID per device, so each device ends up in its own KV namespace
// and cross-device sync silently splits.
if (account?.providerAccountId) {
token.sub = `${account.provider}:${account.providerAccountId}`;
}
return token;
},
async session({ session, token }) {
if (token.sub && session.user) {
(session.user as typeof session.user & { id: string }).id = token.sub;
}
return session;
},
},
});