From 25a03bed421299e6e67a25e688afe784f7fe0063 Mon Sep 17 00:00:00 2001 From: guacamole Date: Mon, 1 May 2023 19:38:49 +0530 Subject: [PATCH 1/7] fix: API endpoints for reset password and a little cleanup --- src/apis/auth.ts | 37 --- src/app.d.ts | 7 +- src/hooks.server.ts | 14 +- src/lib/button-outlined.svelte | 2 + src/lib/client/openregistry.ts | 226 ++++++++++++++++++ src/lib/components/signin.svelte | 88 ++++--- src/lib/formSchemas.ts | 129 +++++----- src/lib/navbar.svelte | 6 +- src/lib/textfield.svelte | 4 +- src/lib/types/user.ts | 3 +- src/routes/(app)/settings/+page.server.ts | 11 + src/routes/(app)/settings/+page.svelte | 144 ++++++----- src/routes/(marketing)/+page.server.ts | 116 ++------- .../(marketing)/auth/[slug]/+page.svelte | 2 +- .../apis/auth/forgot-password/+server.ts | 17 ++ .../apis/auth/reset-password/+server.ts | 33 +++ src/routes/apis/auth/signin/+server.ts | 2 +- src/routes/apis/auth/signup/+server.ts | 2 +- 18 files changed, 526 insertions(+), 317 deletions(-) create mode 100644 src/lib/client/openregistry.ts create mode 100644 src/routes/(app)/settings/+page.server.ts create mode 100644 src/routes/apis/auth/forgot-password/+server.ts create mode 100644 src/routes/apis/auth/reset-password/+server.ts diff --git a/src/apis/auth.ts b/src/apis/auth.ts index f799317b..7603f882 100644 --- a/src/apis/auth.ts +++ b/src/apis/auth.ts @@ -207,43 +207,6 @@ export class Auth extends HttpClient { return resp; }; - public Login = async (email: string, password: string): Promise => { - const path = '/signin'; - - if (!email || !password) { - return Promise.reject('email/password cannot be empty'); - } - const body = { email, password }; - const resp = await this.http.post(path, body); - - return resp; - }; - - public Signup = async ( - username: string, - email: string, - password: string - ): Promise => { - const path = '/signup'; - if (!email || !password) { - return Promise.reject('email/password cannot be empty'); - } - const body = { - username: username, - email: email, - password: password - }; - const resp = await this.http.post(path, body); - return resp; - }; - - public Signout = async (): Promise => { - const path = `/signout`; - - const resp = await this.http.delete(path); - return resp; - }; - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types public GetUserWithSession = async (sessionId: string) => { if (!sessionId) throw new Error('session is empty'); diff --git a/src/app.d.ts b/src/app.d.ts index e767bde2..95174d54 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,4 +1,5 @@ import type { User } from '$apis/auth'; +import { OpenRegistryClient } from '$lib/client/openregistry'; declare global { /// @@ -14,13 +15,17 @@ declare global { password?: string; } interface Locals { + openRegistry: OpenRegistryClient; user: User | null; authenticated: boolean; isRouteProtected: boolean; sessionId: string | null; ghLogsClient: import('@buf/containerish_openregistry.bufbuild_connect-es/services/kone/github_actions/v1/build_logs_connect').GitHubActionsLogsService; - } // interface Platform { } } + declare function fetch( + input: Request | string, + init?: RequestInit | CMRequestInit + ): Promise; } diff --git a/src/hooks.server.ts b/src/hooks.server.ts index d0db2d1e..46798398 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -6,6 +6,7 @@ import { createPromiseClient } from '@bufbuild/connect'; import { GitHubActionsLogsService } from '@buf/containerish_openregistry.bufbuild_connect-es/services/kone/github_actions/v1/build_logs_connect'; import { sequence } from '@sveltejs/kit/hooks'; import { env } from '$env/dynamic/public'; +import { OpenRegistryClient } from '$lib/client/openregistry'; export const authenticationHandler: Handle = async ({ event, resolve }) => { const { cookies, locals, url } = event; @@ -48,4 +49,15 @@ export const isProtectedRoute = (route: string): boolean => { ); }; -export const handle = sequence(authenticationHandler, createProtobufClient); +export const setOpenRegistryClientHandler: Handle = async ({ event, resolve }) => { + const client = new OpenRegistryClient(env.PUBLIC_OPEN_REGISTRY_BACKEND_URL, event.fetch); + event.locals.openRegistry = client; + // these are throwing POJO errors + return await resolve(event); +}; + +export const handle = sequence( + authenticationHandler, + createProtobufClient, + setOpenRegistryClientHandler +); diff --git a/src/lib/button-outlined.svelte b/src/lib/button-outlined.svelte index c5e12983..b80c6f96 100644 --- a/src/lib/button-outlined.svelte +++ b/src/lib/button-outlined.svelte @@ -1,10 +1,12 @@