Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-dee7 committed May 16, 2023
1 parent 8348ea4 commit 82a9ae2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export const authenticationHandler: Handle = async ({ event, resolve }) => {
const { cookies, locals, url } = event;

const sessionId = cookies.get('session_id');
console.log('cookies in hook: ', cookies);
console.log('session id cookie in hook: ', sessionId);
if (sessionId && (!locals.user || !locals.authenticated)) {
const auth = new Auth();
const { data, error, status } = await auth.GetUserWithSession(sessionId);
console.log('user from session: ', data);
console.log('error from session: ', error);
console.log('status from session: ', status);
if (data) {
session.setUser(data);
session.setIsAuthenticated(true);
Expand Down Expand Up @@ -44,7 +49,9 @@ export const createProtobufClient: Handle = async ({ event, resolve }) => {

export const isProtectedRoute = (route: string): boolean => {
return (
route.startsWith('/settings') || route.startsWith('/repositories') || route.startsWith('/apps')
route.startsWith('/settings') ||
route.startsWith('/repositories') ||
route.startsWith('/apps')
);
};

Expand Down
6 changes: 4 additions & 2 deletions src/routes/(marketing)/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export const actions: Actions = {
const user = SignInSchema.parse(formData);
const response = await fetch('/apis/auth/signin', {
method: 'POST',
body: JSON.stringify(user)
body: JSON.stringify(user),
credentials: 'include'
});
const data = await response.json();
if (response.status === 200) {
console.log('response: ', data);
throw redirect(303, '/repositories');
} else {
return fail(response.status, {
Expand Down Expand Up @@ -68,7 +70,7 @@ export const actions: Actions = {
}

throw error(400, {
message: JSON.stringify(await resp.json())
message: JSON.stringify(await response.json())
});
} catch (err) {
return fail(400, {
Expand Down
8 changes: 6 additions & 2 deletions src/routes/apis/auth/signin/+server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignInSchema } from '$lib/formSchemas';
import type { SigninRequestType } from '$lib/types';
import type { SigninRequestType } from '$lib/types/user';
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { env } from '$env/dynamic/public';
Expand All @@ -15,7 +15,8 @@ export const POST: RequestHandler = async ({ fetch, request, cookies }) => {
const url = new URL('/auth/signin', env.PUBLIC_OPEN_REGISTRY_BACKEND_URL);
const response = await fetch(url, {
body: JSON.stringify(body),
method: 'POST'
method: 'POST',
credentials: 'include'
});

if (response.status !== 200) {
Expand All @@ -37,6 +38,9 @@ export const POST: RequestHandler = async ({ fetch, request, cookies }) => {
expires: cookie.expires
});
});

console.log('header cookies: ', cookieList);
console.log('all cookies: ', cookies.getAll());
return json(await response.json(), { status: 200 });
};

Expand Down

0 comments on commit 82a9ae2

Please sign in to comment.