Ship Novya PWA with backend for deployable production use.
Fix production TypeScript builds and add DEPLOY.md so the app can be hosted from this repo. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+40
-19
@@ -1,27 +1,48 @@
|
||||
import { atom } from 'jotai';
|
||||
import type { User, Session } from '@supabase/supabase-js';
|
||||
|
||||
export const sessionAtom = atom<Session | null>(null);
|
||||
export const userAtom = atom<User | null>((get) => {
|
||||
const session = get(sessionAtom);
|
||||
return session?.user ?? null;
|
||||
});
|
||||
export type BackendUser = {
|
||||
id: string;
|
||||
email: string | null;
|
||||
isGuest: boolean;
|
||||
profileComplete: boolean;
|
||||
};
|
||||
|
||||
export type GuestSession = {
|
||||
id: string;
|
||||
isGuest: true;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export const GUEST_SESSION_STORAGE_KEY = 'guest-session';
|
||||
|
||||
const readGuestSession = (): GuestSession | null => {
|
||||
if (typeof window === 'undefined') return null;
|
||||
const raw = localStorage.getItem(GUEST_SESSION_STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as GuestSession;
|
||||
if (!parsed?.id || parsed?.isGuest !== true) return null;
|
||||
return parsed;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const backendUserAtom = atom<BackendUser | null>(null);
|
||||
|
||||
export const isAuthenticatedAtom = atom<boolean>((get) => {
|
||||
const session = get(sessionAtom);
|
||||
return !!session?.user;
|
||||
return !!get(backendUserAtom);
|
||||
});
|
||||
|
||||
export const guestSessionAtom = atom<GuestSession | null>(readGuestSession());
|
||||
export const guestSessionHydratedAtom = atom(false);
|
||||
export const isGuestAtom = atom<boolean>((get) => !!get(guestSessionAtom));
|
||||
|
||||
export const effectiveUserIdAtom = atom<string | null>((get) => {
|
||||
const user = get(backendUserAtom);
|
||||
if (user?.id) return user.id;
|
||||
const guest = get(guestSessionAtom);
|
||||
return guest?.id ?? null;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const authInitialCheckDoneAtom = atom(false);
|
||||
|
||||
Reference in New Issue
Block a user