diff --git a/package.json b/package.json index 173984f9..56510177 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fossorial/pangolin", - "version": "1.0.0", + "version": "1.0.0-beta.1", "private": true, "type": "module", "scripts": { diff --git a/server/auth/resource.ts b/server/auth/resource.ts index 90d85d83..cc20a022 100644 --- a/server/auth/resource.ts +++ b/server/auth/resource.ts @@ -88,19 +88,20 @@ export async function validateResourceSessionToken( .where(eq(resourceSessions.sessionId, resourceSessions.sessionId)); return { resourceSession: null }; } else if ( - !resourceSession.doNotExtend && Date.now() >= resourceSession.expiresAt - resourceSession.sessionLength / 2 ) { - resourceSession.expiresAt = new Date( - Date.now() + resourceSession.sessionLength - ).getTime(); - await db + if (!resourceSession.doNotExtend) { + resourceSession.expiresAt = new Date( + Date.now() + resourceSession.sessionLength + ).getTime(); + await db .update(resourceSessions) .set({ expiresAt: resourceSession.expiresAt }) .where(eq(resourceSessions.sessionId, resourceSession.sessionId)); + } } return { resourceSession }; diff --git a/server/config.ts b/server/config.ts index 13e6c14f..ea8de136 100644 --- a/server/config.ts +++ b/server/config.ts @@ -14,7 +14,7 @@ const portSchema = z.number().positive().gt(0).lte(65535); const environmentSchema = z.object({ app: z.object({ - base_url: z.string().url(), + base_url: z.string().url().transform((url) => url.toLowerCase()), log_level: z.enum(["debug", "info", "warn", "error"]), save_logs: z.boolean() }), @@ -22,9 +22,8 @@ const environmentSchema = z.object({ external_port: portSchema, internal_port: portSchema, next_port: portSchema, - internal_hostname: z.string(), + internal_hostname: z.string().transform((url) => url.toLowerCase()), secure_cookies: z.boolean(), - signup_secret: z.string().optional(), session_cookie_name: z.string(), resource_session_cookie_name: z.string() }), @@ -36,7 +35,7 @@ const environmentSchema = z.object({ }), gerbil: z.object({ start_port: portSchema, - base_endpoint: z.string(), + base_endpoint: z.string().transform((url) => url.toLowerCase()), use_subdomain: z.boolean(), subnet_group: z.string(), block_size: z.number().positive().gt(0) diff --git a/server/routers/resource/authWithAccessToken.ts b/server/routers/resource/authWithAccessToken.ts index 997f9380..5256020a 100644 --- a/server/routers/resource/authWithAccessToken.ts +++ b/server/routers/resource/authWithAccessToken.ts @@ -105,7 +105,7 @@ export async function authWithAccessToken( ); } - const validCode = await verifyPassword(tokenItem.tokenHash, accessToken); + const validCode = await verifyPassword(accessToken, tokenItem.tokenHash); if (!validCode) { return next( @@ -132,7 +132,7 @@ export async function authWithAccessToken( accessTokenId: tokenItem.accessTokenId, sessionLength: tokenItem.sessionLength, expiresAt: tokenItem.expiresAt, - doNotExtend: tokenItem.expiresAt ? false : true + doNotExtend: tokenItem.expiresAt ? true : false }); const cookieName = `${config.server.resource_session_cookie_name}_${resource.resourceId}`; const cookie = serializeResourceSessionCookie(cookieName, token); diff --git a/server/routers/resource/createResource.ts b/server/routers/resource/createResource.ts index d6ae47f2..5ce49ad5 100644 --- a/server/routers/resource/createResource.ts +++ b/server/routers/resource/createResource.ts @@ -51,7 +51,9 @@ export async function createResource( ); } - const { name, subdomain } = parsedBody.data; + let { name, subdomain } = parsedBody.data; + + subdomain = subdomain.toLowerCase(); // always to lower case // Validate request params const parsedParams = createResourceParamsSchema.safeParse(req.params); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index d9792294..6ad04643 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -5,6 +5,10 @@ import { Toaster } from "@/components/ui/toaster"; import { ThemeProvider } from "@app/providers/ThemeProvider"; import EnvProvider from "@app/providers/EnvProvider"; import { Separator } from "@app/components/ui/separator"; +import { cache } from "react"; +import { verifySession } from "@app/lib/auth/verifySession"; +import Header from "@app/components/Header"; +import UserProvider from "@app/providers/UserProvider"; export const metadata: Metadata = { title: `Dashboard - Pangolin`, @@ -20,6 +24,9 @@ export default async function RootLayout({ }>) { const version = process.env.APP_VERSION; + const getUser = cache(verifySession); + const user = await getUser(); + return (
@@ -39,8 +46,10 @@ export default async function RootLayout({ ENVIRONMENT: process.env.ENVIRONMENT as string, EMAIL_ENABLED: process.env.EMAIL_ENABLED as string, // optional - DISABLE_USER_CREATE_ORG: process.env.DISABLE_USER_CREATE_ORG, - DISABLE_SIGNUP_WITHOUT_INVITE: process.env.DISABLE_SIGNUP_WITHOUT_INVITE, + DISABLE_USER_CREATE_ORG: + process.env.DISABLE_USER_CREATE_ORG, + DISABLE_SIGNUP_WITHOUT_INVITE: + process.env.DISABLE_SIGNUP_WITHOUT_INVITE }} > {children} @@ -49,24 +58,23 @@ export default async function RootLayout({