-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhooks.server.ts
More file actions
39 lines (34 loc) · 1.18 KB
/
hooks.server.ts
File metadata and controls
39 lines (34 loc) · 1.18 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
import * as SentryNode from '@sentry/node';
import crypto from 'crypto';
import { createSupabaseServerClient } from '@supabase/auth-helpers-sveltekit';
import { PUBLIC_SUPABASE_URL, PUBLIC_SENTRY_DSN } from '$env/static/public';
import { PRIVATE_SUPABASE_SERVICE_KEY } from '$env/static/private'
import type { Handle, HandleServerError } from '@sveltejs/kit';
import type { Database } from '$lib/types/db';
SentryNode.init({
dsn: PUBLIC_SENTRY_DSN
})
export const handleError: HandleServerError = ({ error, event }) => {
const errorId = crypto.randomUUID();
SentryNode.captureException(error, {
contexts: { sveltekit: { event, errorId } },
});
return {
message: 'Der skete en uventet fejl.',
errorId
}
}
export const handle: Handle = (async ({ event, resolve }) => {
event.locals.supabase = createSupabaseServerClient<Database>({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PRIVATE_SUPABASE_SERVICE_KEY,
event
});
event.locals.getSession = async () => {
const {
data: { session }
} = await event.locals.supabase.auth.getSession();
return session;
};
return resolve(event);
});