diff --git a/bunfig.toml b/bunfig.toml index 6a121e8a..e233d92d 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,4 +1,5 @@ [serve.static] +env = "PUBLIC_*" plugins = ["bun-plugin-tailwind"] [install] diff --git a/packages/api/src/middleware/auth.test.ts b/packages/api/src/middleware/auth.test.ts index 6d48bcc4..951812e7 100644 --- a/packages/api/src/middleware/auth.test.ts +++ b/packages/api/src/middleware/auth.test.ts @@ -32,7 +32,7 @@ describe('authMiddleware', () => { beforeEach(() => { vi.resetAllMocks() - delete process.env.REVIEWER_READ_ONLY + delete process.env.PUBLIC_DEMO_MODE }) it('allows access when authenticated', async () => { @@ -54,7 +54,7 @@ describe('authMiddleware', () => { describe('read-only mode', () => { beforeEach(() => { - process.env.REVIEWER_READ_ONLY = '1' + process.env.PUBLIC_DEMO_MODE = '1' }) it('allows GET for reviewer', async () => { diff --git a/packages/api/src/middleware/auth.ts b/packages/api/src/middleware/auth.ts index c0ac0278..3cd043d9 100644 --- a/packages/api/src/middleware/auth.ts +++ b/packages/api/src/middleware/auth.ts @@ -29,7 +29,7 @@ export const authMiddleware = createMiddleware<{ c.set('user', user) - if (process.env.REVIEWER_READ_ONLY === '1') { + if (process.env.PUBLIC_DEMO_MODE === '1') { const method = c.req.method.toUpperCase() const path = c.req.path if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method) && !path.endsWith('/search')) { diff --git a/packages/webui/routes/login.tsx b/packages/webui/routes/login.tsx index e9e58551..c7d64ec3 100644 --- a/packages/webui/routes/login.tsx +++ b/packages/webui/routes/login.tsx @@ -1,18 +1,18 @@ import { client } from '@/ui/api/client' -import { useQuery } from '@tanstack/react-query' +import { AuthLayout } from '@/ui/components/auth-layout' import { Button } from '@/ui/components/ui/button' +import { ShumaiLogo } from '@/ui/components/ui/icons' import { Input } from '@/ui/components/ui/input' import { Label } from '@/ui/components/ui/label' +import { signIn } from '@/ui/lib/auth-client' import { useAuthStore } from '@/ui/stores/auth' import { zodResolver } from '@hookform/resolvers/zod' +import { useQuery } from '@tanstack/react-query' import { createFileRoute, redirect, useNavigate } from '@tanstack/react-router' +import { ArrowRight, Loader2, Lock, LogIn, Mail } from 'lucide-react' import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { z } from 'zod' -import { signIn } from '@/ui/lib/auth-client' -import { Loader2, Mail, Lock, ArrowRight, LogIn } from 'lucide-react' -import { ShumaiLogo } from '@/ui/components/ui/icons' -import { AuthLayout } from '@/ui/components/auth-layout' const loginSchema = z.object({ email: z.string().email('Invalid email address'), @@ -27,6 +27,13 @@ function LoginPage() { const [error, setError] = useState(null) const [loading, setLoading] = useState(false) + let isDemoEnv + try { + isDemoEnv = process.env.PUBLIC_DEMO_MODE === '1' + } catch { + isDemoEnv = false + } + const { data: signupInfo, isLoading: isSignupInfoLoading } = useQuery({ queryKey: ['/signup-info'], queryFn: async () => { @@ -88,6 +95,15 @@ function LoginPage() {

+ {isDemoEnv && ( +
+

+ Demo Access: Use "foo@bar.com" as the email and{' '} + "foo" as the password to login. +

+
+ )} + {error && (
{error}