-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
48 lines (43 loc) · 1.33 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
import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle";
import { Lucia } from "lucia";
import { sessionTable, userTable } from "@/db/schema";
import db from "@/db/drizzle";
import { Google } from "arctic";
import { decrypt } from "./lib/enc";
const adapter = new DrizzlePostgreSQLAdapter(db, sessionTable, userTable); // your adapter
export const lucia = new Lucia(adapter, {
sessionCookie: {
// this sets cookies with super long expiration
// since Next.js doesn't allow Lucia to extend cookie expiration when rendering pages
expires: false,
attributes: {
// set to `true` when using HTTPS
secure: process.env.NODE_ENV === "production",
},
},
getUserAttributes: (attributes) => {
return {
// attributes has the type of DatabaseUserAttributes
email: decrypt(attributes.email),
image: decrypt(attributes.image),
name: decrypt(attributes.name),
};
},
});
export const redirectURI = `${
process.env.NODE_ENV === "production"
? "https://urbanpulse.asia"
: "http://localhost:5420"
}/auth/`;
export const google = new Google(
process.env.GOOGLE_CLIENT_ID || "",
process.env.GOOGLE_CLIENT_SECRET || "",
redirectURI
);
// IMPORTANT!
declare module "lucia" {
interface Register {
Lucia: typeof lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
}
}