-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
63 lines (57 loc) · 1.67 KB
/
auth.ts
File metadata and controls
63 lines (57 loc) · 1.67 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import NextAuth from "next-auth"
import "next-auth/jwt"
import Scalekit from "./providers/scalekit"
import { createStorage } from "unstorage"
import memoryDriver from "unstorage/drivers/memory"
import vercelKVDriver from "unstorage/drivers/vercel-kv"
import { UnstorageAdapter } from "@auth/unstorage-adapter"
const storage = createStorage({
driver: process.env.VERCEL
? vercelKVDriver({
url: process.env.AUTH_KV_REST_API_URL,
token: process.env.AUTH_KV_REST_API_TOKEN,
env: false,
})
: memoryDriver(),
})
export const { handlers, auth, signIn, signOut } = NextAuth({
debug: !!process.env.AUTH_DEBUG,
theme: { logo: "https://authjs.dev/img/logo-sm.png" },
adapter: UnstorageAdapter(storage),
providers: [
Scalekit({
issuer: process.env.AUTH_SCALEKIT_ISSUER!,
clientId: process.env.AUTH_SCALEKIT_ID!,
clientSecret: process.env.AUTH_SCALEKIT_SECRET!,
connectionId: process.env.AUTH_SCALEKIT_CONNECTION_ID,
}),
],
basePath: "/auth",
session: { strategy: "jwt" },
callbacks: {
authorized({ request, auth }) {
const { pathname } = request.nextUrl
if (pathname === "/middleware-example") return !!auth
return true
},
jwt({ token, trigger, session }) {
if (trigger === "update") token.name = session.user.name
return token
},
async session({ session, token }) {
if (token?.accessToken) session.accessToken = token.accessToken
return session
},
},
experimental: { enableWebAuthn: true },
})
declare module "next-auth" {
interface Session {
accessToken?: string
}
}
declare module "next-auth/jwt" {
interface JWT {
accessToken?: string
}
}