This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
auth.ts
89 lines (85 loc) · 2.48 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
import { cache } from 'react';
import { cookies } from 'next/headers';
import { DrizzleMySQLAdapter } from '@lucia-auth/adapter-drizzle';
import { GitHub } from 'arctic';
import { Lucia } from 'lucia';
import type { Session, User } from 'lucia';
import { sessions, users } from '~/db/schemas/auth';
import { env } from '~/env.mjs';
/**
* @enable Drizzle
*/
// import { db } from './db';
/**
* @enable LuciaAuth
*/
// const adapter = new DrizzleMySQLAdapter(db, sessions, users);
//
// 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: {
// secure: env.NODE_ENV === 'production', // `true` when using HTTPS
// },
// },
// getUserAttributes: (attributes) => {
// return {
// githubId: attributes.githubId,
// };
// },
// });
//
// export const validateRequest = cache(
// async (): Promise<
// { user: User; session: Session } | { user: null; session: null }
// > => {
// const sessionId = cookies().get(lucia.sessionCookieName)?.value ?? null;
// if (!sessionId) {
// return { user: null, session: null };
// }
//
// const result = await lucia.validateSession(sessionId);
// // Next.js throws when you attempt to set cookie when rendering page
// try {
// if (result.session && result.session.fresh) {
// const sessionCookie = lucia.createSessionCookie(result.session.id);
// cookies().set(
// sessionCookie.name,
// sessionCookie.value,
// sessionCookie.attributes
// );
// }
// if (!result.session) {
// const sessionCookie = lucia.createBlankSessionCookie();
// cookies().set(
// sessionCookie.name,
// sessionCookie.value,
// sessionCookie.attributes
// );
// }
// } catch {}
// return result;
// }
// );
//
// export const github = new GitHub(env.AUTH_GITHUB_ID, env.AUTH_GITHUB_SECRET);
//
// declare module 'lucia' {
// interface Register {
// Lucia: typeof lucia;
// DatabaseUserAttributes: Omit<typeof users._.model.select, 'id'>;
// }
// }
const authProviders = [
/**
* @enable LuciaAuth
*/
'github',
] as const;
export type AuthProvider = (typeof authProviders)[number];
export const authRedirects = {
afterLogin: '/examples/profile',
afterLogout: '/examples/profile',
} as const;