From 9a4357394ac7ff7eac80ac251e8c2bae0147071d Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 26 Apr 2024 17:05:16 +0200 Subject: [PATCH] Fix: make locals global --- front/src/env.d.ts | 19 +++++++++++++------ front/src/pages/account/index.astro | 2 +- front/src/pages/account/login.astro | 7 ++----- front/src/pages/account/logout.astro | 2 +- front/src/pages/account/register.astro | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/front/src/env.d.ts b/front/src/env.d.ts index d858407..d0ad1e8 100644 --- a/front/src/env.d.ts +++ b/front/src/env.d.ts @@ -16,10 +16,17 @@ interface ImportMeta { } -// eslint-disable-next-line @typescript-eslint/no-namespace -declare namespace App { - // eslint-disable-next-line @typescript-eslint/no-empty-interface - export interface Locals { - pb: PocketBase - } +// declare namespace App { +// interface Locals { +// pb: PocketBase +// } +// } + + +declare global { + namespace App { + interface Locals { + pb: PocketBase + } + } } diff --git a/front/src/pages/account/index.astro b/front/src/pages/account/index.astro index 39a434b..84f7cad 100644 --- a/front/src/pages/account/index.astro +++ b/front/src/pages/account/index.astro @@ -3,7 +3,7 @@ import Layout from 'layouts/Layout.astro' import PocketBase from 'pocketbase' -const pb = Astro.locals.pb as PocketBase +const pb = Astro.locals.pb const auth = pb.authStore const user = auth.model diff --git a/front/src/pages/account/login.astro b/front/src/pages/account/login.astro index 6f3cd39..4561636 100644 --- a/front/src/pages/account/login.astro +++ b/front/src/pages/account/login.astro @@ -4,7 +4,7 @@ import AstroUtils from "libs/AstroUtils"; import PocketBase from 'pocketbase' -const pb = Astro.locals.pb as PocketBase +const pb = Astro.locals.pb if(pb.authStore.isValid){ return Astro.redirect("/account") @@ -13,10 +13,7 @@ if(pb.authStore.isValid){ const res = await AstroUtils.wrap(async () => { if (Astro.request.method !== 'POST') { return - } - // FIXME checké si utilisateur deja connecté - const locals = Astro.locals - + } const form = await Astro.request.formData(); const request = { user: form.get("username") as string, diff --git a/front/src/pages/account/logout.astro b/front/src/pages/account/logout.astro index 28472f1..01eb3ca 100644 --- a/front/src/pages/account/logout.astro +++ b/front/src/pages/account/logout.astro @@ -2,7 +2,7 @@ import PocketBase from 'pocketbase' -const pb = Astro.locals.pb as PocketBase +const pb = Astro.locals.pb if(pb.authStore.isValid){ pb.authStore.clear() diff --git a/front/src/pages/account/register.astro b/front/src/pages/account/register.astro index f016d0f..51fe66a 100644 --- a/front/src/pages/account/register.astro +++ b/front/src/pages/account/register.astro @@ -4,7 +4,7 @@ import AstroUtils from 'libs/AstroUtils'; import PocketBase from 'pocketbase' -const pb = Astro.locals.pb as PocketBase +const pb = Astro.locals.pb if(pb.authStore.isValid){ return Astro.redirect("/account")