-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
41 lines (35 loc) · 936 Bytes
/
index.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
import { AppwriteService, appwrite } from '$lib/appwrite';
import * as cookie from 'cookie';
export async function get({ request }: any) {
// Get cookie from request
const cookies = cookie.parse(request.headers.get("cookie") || '');
const projectId = 'svelteKitSsr';
const authCookie = cookies[`a_session_${projectId.toLowerCase()}_legacy`];
// If cookies present, set it on Appwerite SDK client
if (authCookie) {
const authCookies: any = {};
authCookies[`a_session_${projectId}`] = authCookie;
appwrite.headers['X-Fallback-Cookies'] = authCookies;
}
// Get account info
try {
const profile = await AppwriteService.getAccount();
return {
body: {
profile: {
email: profile.email,
name: profile.name
}
}
};
} catch (err) {
console.log(err);
// Its fine, we dont have profile
}
// If get failed, return no profile (user not signed in)
return {
body: {
profile: null
}
};
}