forked from nextauthjs/next-auth-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
57 lines (53 loc) · 1.45 KB
/
auth.ts
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
import NextAuth from "next-auth"
import "next-auth/jwt"
import CredentialsProvider from "next-auth/providers/credentials"
import type { NextAuthConfig } from "next-auth"
const config = {
theme: { logo: "https://authjs.dev/img/logo-sm.png" },
providers: [
CredentialsProvider({
async authorize(credentials: Partial<Record<string, unknown>>): Promise<any> {
return {
'authenticated': true,
'username': credentials.username
}
}
})
],
basePath: "/auth",
callbacks: {
authorized({ request, auth }) {
const { pathname } = request.nextUrl
if (pathname === "/middleware-example") return !!auth
return true
},
jwt({ token, trigger, session, account }) {
if (trigger === "update") token.name = session.user.name
if (account?.provider === "keycloak") {
return { ...token, accessToken: account.access_token }
}
return token
},
async session({ session, token }) {
if (token?.accessToken) {
session.accessToken = token.accessToken
}
return session
},
},
experimental: {
enableWebAuthn: true,
},
debug: process.env.NODE_ENV !== "production" ? true : false,
} satisfies NextAuthConfig
export const { handlers, auth, signIn, signOut } = NextAuth(config)
declare module "next-auth" {
interface Session {
accessToken?: string
}
}
declare module "next-auth/jwt" {
interface JWT {
accessToken?: string
}
}