Skip to content

Commit 82a9ae2

Browse files
committed
WIP
1 parent 8348ea4 commit 82a9ae2

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/hooks.server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ export const authenticationHandler: Handle = async ({ event, resolve }) => {
1111
const { cookies, locals, url } = event;
1212

1313
const sessionId = cookies.get('session_id');
14+
console.log('cookies in hook: ', cookies);
15+
console.log('session id cookie in hook: ', sessionId);
1416
if (sessionId && (!locals.user || !locals.authenticated)) {
1517
const auth = new Auth();
1618
const { data, error, status } = await auth.GetUserWithSession(sessionId);
19+
console.log('user from session: ', data);
20+
console.log('error from session: ', error);
21+
console.log('status from session: ', status);
1722
if (data) {
1823
session.setUser(data);
1924
session.setIsAuthenticated(true);
@@ -44,7 +49,9 @@ export const createProtobufClient: Handle = async ({ event, resolve }) => {
4449

4550
export const isProtectedRoute = (route: string): boolean => {
4651
return (
47-
route.startsWith('/settings') || route.startsWith('/repositories') || route.startsWith('/apps')
52+
route.startsWith('/settings') ||
53+
route.startsWith('/repositories') ||
54+
route.startsWith('/apps')
4855
);
4956
};
5057

src/routes/(marketing)/+page.server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ export const actions: Actions = {
2020
const user = SignInSchema.parse(formData);
2121
const response = await fetch('/apis/auth/signin', {
2222
method: 'POST',
23-
body: JSON.stringify(user)
23+
body: JSON.stringify(user),
24+
credentials: 'include'
2425
});
2526
const data = await response.json();
2627
if (response.status === 200) {
28+
console.log('response: ', data);
2729
throw redirect(303, '/repositories');
2830
} else {
2931
return fail(response.status, {
@@ -68,7 +70,7 @@ export const actions: Actions = {
6870
}
6971

7072
throw error(400, {
71-
message: JSON.stringify(await resp.json())
73+
message: JSON.stringify(await response.json())
7274
});
7375
} catch (err) {
7476
return fail(400, {

src/routes/apis/auth/signin/+server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SignInSchema } from '$lib/formSchemas';
2-
import type { SigninRequestType } from '$lib/types';
2+
import type { SigninRequestType } from '$lib/types/user';
33
import { json } from '@sveltejs/kit';
44
import type { RequestHandler } from './$types';
55
import { env } from '$env/dynamic/public';
@@ -15,7 +15,8 @@ export const POST: RequestHandler = async ({ fetch, request, cookies }) => {
1515
const url = new URL('/auth/signin', env.PUBLIC_OPEN_REGISTRY_BACKEND_URL);
1616
const response = await fetch(url, {
1717
body: JSON.stringify(body),
18-
method: 'POST'
18+
method: 'POST',
19+
credentials: 'include'
1920
});
2021

2122
if (response.status !== 200) {
@@ -37,6 +38,9 @@ export const POST: RequestHandler = async ({ fetch, request, cookies }) => {
3738
expires: cookie.expires
3839
});
3940
});
41+
42+
console.log('header cookies: ', cookieList);
43+
console.log('all cookies: ', cookies.getAll());
4044
return json(await response.json(), { status: 200 });
4145
};
4246

0 commit comments

Comments
 (0)