♻️ refactor: update middleware.ts

swadhinbiswas committed 3 months ago
5c45620
1 parent c00e371
commit 5c45620
1 file changed
+10 -1
Showing 1 changed file+10-1
▼src/middleware.ts
+10-1
51
51
if (user) {
52
52
context.locals.user = user;
53
53
}
54
+ // Populate session for logout and other session-aware handlers
55
+ if (tokenPayload.sessionId) {
56
+ const session = await db.query.sessions?.findFirst({
57
+ where: eq(schema.sessions.id, tokenPayload.sessionId),
58
+ });
59
+ if (session) {
60
+ context.locals.session = session;
61
+ }
62
+ }
54
63
}
55
64
} catch {
56
65
// Auth failures are non-fatal — user stays null (anonymous)
123
132
if (!response.headers.has("Content-Security-Policy")) {
124
133
response.headers.set(
125
134
"Content-Security-Policy",
126
- "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self'",
135
+ "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' data: https://fonts.gstatic.com; img-src 'self' data: https: blob:; connect-src 'self' https:;",
127
136
);
128
137
}
129
138
130
139