diff --git a/bun.lockb b/bun.lockb index 61bc091..68fabb9 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/components/header.tsx b/src/components/header.tsx index b1db00e..20167a6 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -3,10 +3,12 @@ import { Html } from "@kitajs/html"; export const Header = ({ loggedIn, accountRegistration, + allowUnauthenticated, webroot = "", }: { loggedIn?: boolean; accountRegistration?: boolean; + allowUnauthenticated?: boolean; webroot?: string; }) => { let rightNav: JSX.Element; @@ -24,17 +26,19 @@ export const Header = ({ History -
  • - - Logout - -
  • + {!allowUnauthenticated ? ( +
  • + + Logout + +
  • + ) : null} ); } else { diff --git a/src/index.tsx b/src/index.tsx index c609af2..859ffb4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -215,6 +215,7 @@ const app = new Elysia({
    @@ -340,6 +341,7 @@ const app = new Elysia({
    @@ -457,36 +459,19 @@ const app = new Elysia({ return redirect(`${WEBROOT}/login`, 302); }) .get("/", async ({ jwt, redirect, cookie: { auth, jobId } }) => { - if (FIRST_RUN) { - return redirect(`${WEBROOT}/setup`, 302); - } + if (!ALLOW_UNAUTHENTICATED) { + if (FIRST_RUN) { + return redirect(`${WEBROOT}/setup`, 302); + } - if (!auth?.value && !ALLOW_UNAUTHENTICATED) { - return redirect(`${WEBROOT}/login`, 302); + if (!auth?.value) { + return redirect(`${WEBROOT}/login`, 302); + } } // validate jwt let user: ({ id: string } & JWTPayloadSpec) | false = false; - if (auth?.value) { - user = await jwt.verify(auth.value); - - if (user !== false && user.id) { - if (Number.parseInt(user.id) < 2 ** 24 || !ALLOW_UNAUTHENTICATED) { - // make sure user exists in db - const existingUser = db - .query("SELECT * FROM users WHERE id = ?") - .as(User) - .get(user.id); - - if (!existingUser) { - if (auth?.value) { - auth.remove(); - } - return redirect(`${WEBROOT}/login`, 302); - } - } - } - } else if (ALLOW_UNAUTHENTICATED) { + if (ALLOW_UNAUTHENTICATED) { const newUserId = String( randomInt( 2 ** 24, @@ -512,6 +497,25 @@ const app = new Elysia({ maxAge: 24 * 60 * 60, sameSite: "strict", }); + } else if (auth?.value) { + user = await jwt.verify(auth.value); + + if (user !== false && user.id) { + if (Number.parseInt(user.id) < 2 ** 24 || !ALLOW_UNAUTHENTICATED) { + // make sure user exists in db + const existingUser = db + .query("SELECT * FROM users WHERE id = ?") + .as(User) + .get(user.id); + + if (!existingUser) { + if (auth?.value) { + auth.remove(); + } + return redirect(`${WEBROOT}/login`, 302); + } + } + } } if (!user) { @@ -547,7 +551,11 @@ const app = new Elysia({ return ( <> -
    +

    Convert

    @@ -951,7 +959,11 @@ const app = new Elysia({ return ( <> -
    +

    Results

    @@ -1038,7 +1050,11 @@ const app = new Elysia({ return ( <> -
    +
    @@ -1284,7 +1300,11 @@ const app = new Elysia({ return ( <> -
    +

    Converters