forked from hashdocs/hashdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
74 lines (59 loc) · 1.89 KB
/
middleware.ts
File metadata and controls
74 lines (59 loc) · 1.89 KB
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
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
export const config = {
matcher: ['/login', '/dashboard'],
};
export async function middleware(req: NextRequest) {
const res = NextResponse.next();
const url = req.nextUrl.pathname.split('/');
if (url.length < 2) return res;
// Handle main routes
switch (url.at(1)) {
case '':
// case 'login': {
// const supabase = createMiddlewareClient(req, res);
// const {
// data: { session },
// } = await supabase.auth.getSession();
// if (session?.expires_in) {
// return NextResponse.redirect(new URL('/dashboard', req.url));
// }
// break;
// }
case 'dashboard': {
// const supabase = createMiddlewareClient(req, res);
// const {
// data: { session },
// } = await supabase.auth.getSession();
// if (!session?.access_token) {
// await supabase.auth.signOut();
// return NextResponse.redirect(new URL('/login', req.url));
// }
// if (url.length == 2) {
// const {
// data: { session },
// } = await supabase.auth.getSession();
// if (!session?.access_token) {
// return NextResponse.redirect(new URL('/login', req.url));
// }
// const parsed_token = JSON.parse(
// Buffer.from(session.access_token.split('.')[1], 'base64').toString()
// );
// if (parsed_token.app_metadata['org_ids'].length === 1) {
// return NextResponse.redirect(
// new URL(
// `/dashboard/${parsed_token.app_metadata['org_ids'].at(
// 0
// )}/documents`,
// req.url
// )
// );
// }
// }
break;
}
default:
break;
}
return res;
}