-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
91 lines (85 loc) · 3.19 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import NextAuth from 'next-auth';
import 'next-auth/jwt';
import Apple from 'next-auth/providers/apple';
// import Atlassian from "next-auth/providers/atlassian"
import Auth0 from 'next-auth/providers/auth0';
import AzureB2C from 'next-auth/providers/azure-ad-b2c';
import BankIDNorway from 'next-auth/providers/bankid-no';
import BoxyHQSAML from 'next-auth/providers/boxyhq-saml';
import Cognito from 'next-auth/providers/cognito';
import Coinbase from 'next-auth/providers/coinbase';
import Discord from 'next-auth/providers/discord';
import Dropbox from 'next-auth/providers/dropbox';
import Facebook from 'next-auth/providers/facebook';
import GitHub from 'next-auth/providers/github';
import GitLab from 'next-auth/providers/gitlab';
import Google from 'next-auth/providers/google';
import Hubspot from 'next-auth/providers/hubspot';
import Keycloak from 'next-auth/providers/keycloak';
import LinkedIn from 'next-auth/providers/linkedin';
import MicrosoftEntraId from 'next-auth/providers/microsoft-entra-id';
import Netlify from 'next-auth/providers/netlify';
import Okta from 'next-auth/providers/okta';
import Passage from 'next-auth/providers/passage';
import Passkey from 'next-auth/providers/passkey';
import Pinterest from 'next-auth/providers/pinterest';
import Reddit from 'next-auth/providers/reddit';
import Slack from 'next-auth/providers/slack';
import Salesforce from 'next-auth/providers/salesforce';
import Spotify from 'next-auth/providers/spotify';
import Twitch from 'next-auth/providers/twitch';
import Twitter from 'next-auth/providers/twitter';
import Vipps from 'next-auth/providers/vipps';
import WorkOS from 'next-auth/providers/workos';
import Zoom from 'next-auth/providers/zoom';
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: [Google],
basePath: '/auth',
session: { strategy: 'jwt' },
secret: process.env.AUTH_SECRET,
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 },
});
declare module 'next-auth' {
interface Session {
accessToken?: string;
}
}
declare module 'next-auth/jwt' {
interface JWT {
accessToken?: string;
}
}