-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
46 lines (42 loc) · 1.39 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
import { FirestoreAdapter } from "@auth/firebase-adapter";
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import type { Provider } from "next-auth/providers";
import { revalidateTag } from "next/cache";
import { authFirestore } from "@/utils/authFirestore";
import { CacheTag, getCacheTagSpecific } from "@/utils/cacheTags";
import Seznam from "@/utils/seznam.provider";
const providers: Provider[] = [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
Seznam({
clientId: process.env.SEZNAM_CLIENT_ID,
clientSecret: process.env.SEZNAM_CLIENT_SECRET,
}),
];
export const providerMap = providers.map((provider) => {
if (typeof provider === "function") {
const providerData = provider();
return { id: providerData.id, name: providerData.name };
} else {
return { id: provider.id, name: provider.name };
}
});
export const { auth, handlers, signIn, signOut } = NextAuth({
trustHost: true,
providers,
adapter: FirestoreAdapter(authFirestore),
pages: {
signIn: "/signin",
},
events: {
async createUser(message) {
revalidateTag(CacheTag.UsersCount);
},
async updateUser(message) {
revalidateTag(getCacheTagSpecific(CacheTag.User, message.user.id));
},
},
});