-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
62 lines (57 loc) · 1.57 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
import "server-only";
import NextAuth from "next-auth";
import GitHubProvider from "next-auth/providers/github";
import AuthentikProvider from "next-auth/providers/authentik";
import { TypeORMAdapter } from "@auth/typeorm-adapter";
import * as entities from "@/app/lib/db/entities/User";
import { config } from "@/app.config";
import Gitee from "@/app/lib/provider/gitee";
import { Provider } from "@auth/core/providers";
import { DataSourceOptions } from "typeorm";
const authDbOption: DataSourceOptions = {
database: config.db.database,
synchronize: true,
logging: false,
type: "oracle",
host: config.db.host,
port: Number(config.db.port),
username: config.db.username,
password: config.db.password,
sid: config.db.sid,
};
const providers: Provider[] = [
GitHubProvider({
clientId: config.auth.github.id,
clientSecret: config.auth.github.secret,
}),
Gitee({
clientId: config.auth.gitee.id,
clientSecret: config.auth.gitee.secret,
}),
AuthentikProvider({
clientId: config.auth.autho.id,
clientSecret: config.auth.autho.secret,
issuer: config.auth.autho.issuer,
profile(profile) {
return {
...profile,
id: profile.sub,
name: profile.nickname,
};
},
}),
];
export const providerMap = providers.map((provider) => {
if (typeof provider === "function") {
return provider();
} else {
return { ...provider };
}
});
export const { signIn, signOut, auth, handlers } = NextAuth({
adapter: TypeORMAdapter(authDbOption, { entities }),
providers,
pages: {
signIn: config.path.login,
},
});