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 d405471 commit 20dde3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export const authenticationHandler: Handle = async ({ event, resolve }) => {
const { cookies, locals, url } = event;

const sessionId = cookies.get('session_id');
console.log('session id in hooks: ', sessionId);
console.log('cookies id in hooks: ', cookies.getAll());
if (sessionId && (!locals.user || !locals.authenticated)) {
const user = await locals.openRegistry.getUserBySession(sessionId);
console.log('user id in hooks: ', user);
if (user) {
session.setUser(user);
session.setIsAuthenticated(true);
Expand Down Expand Up @@ -43,7 +46,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
10 changes: 8 additions & 2 deletions src/lib/client/openregistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ export class OpenRegistryClient {
cookie: `session_id=${sessionId}`
}
});
return OpenRegistryUserSchema.parse(await response.json());
const data = await response.json();
console.log('status in getUserBySession: ', response.status);
console.log('data in getUserBySession: ', data);
return OpenRegistryUserSchema.parse(data);
} catch (err) {
console.warn('error getting user from session: ', err);
return null;
Expand Down Expand Up @@ -281,7 +284,10 @@ export class OpenRegistryClient {
credentialCreationOpts: CredentialCreationOptionsJSON
): Promise<WebAuthnFinishRegisterResponseType> {
const options = parseCreationOptionsFromJSON(credentialCreationOpts);
const url = new URL('/auth/webauthn/registration/finish', env.PUBLIC_OPEN_REGISTRY_BACKEND_URL);
const url = new URL(
'/auth/webauthn/registration/finish',
env.PUBLIC_OPEN_REGISTRY_BACKEND_URL
);
url.searchParams.set('username', username);
let body: RegistrationPublicKeyCredential;
try {
Expand Down

0 comments on commit 20dde3b

Please sign in to comment.