Harte Paywall
This commit is contained in:
@@ -4,14 +4,15 @@ import { getConfiguredBackendRootUrl } from '../utils/backendUrl';
|
||||
|
||||
const SESSION_KEY = 'greenlens_session_v3';
|
||||
|
||||
export interface AuthSession {
|
||||
userId: number; // local SQLite id (for plants/settings queries)
|
||||
serverUserId: string; // server-side user id (in JWT)
|
||||
email: string;
|
||||
name: string;
|
||||
token: string; // JWT from server
|
||||
loggedInAt: string;
|
||||
}
|
||||
export interface AuthSession {
|
||||
userId: number; // local SQLite id (for plants/settings queries)
|
||||
serverUserId: string; // server-side user id (in JWT)
|
||||
email: string;
|
||||
name: string;
|
||||
token: string; // JWT from server
|
||||
loggedInAt: string;
|
||||
isNewUser?: boolean;
|
||||
}
|
||||
|
||||
// ─── Internal helpers ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -19,7 +20,7 @@ const clearStoredSession = async (): Promise<void> => {
|
||||
await SecureStore.deleteItemAsync(SESSION_KEY);
|
||||
};
|
||||
|
||||
const authPost = async (path: string, body: object): Promise<{ userId: string; email: string; name: string; token: string }> => {
|
||||
const authPost = async (path: string, body: object): Promise<{ userId: string; email: string; name: string; token: string; isNewUser?: boolean }> => {
|
||||
const backendUrl = getConfiguredBackendRootUrl();
|
||||
const hasBackendUrl = Boolean(backendUrl);
|
||||
const url = hasBackendUrl ? `${backendUrl}${path}` : path;
|
||||
@@ -49,17 +50,18 @@ const authPost = async (path: string, body: object): Promise<{ userId: string; e
|
||||
return data as any;
|
||||
};
|
||||
|
||||
const buildSession = (data: { userId: string; email: string; name: string; token: string }): AuthSession => {
|
||||
const buildSession = (data: { userId: string; email: string; name: string; token: string; isNewUser?: boolean }): AuthSession => {
|
||||
const localUser = AuthDb.ensureLocalUser(data.email, data.name);
|
||||
return {
|
||||
userId: localUser.id,
|
||||
serverUserId: data.userId,
|
||||
email: data.email,
|
||||
name: data.name,
|
||||
token: data.token,
|
||||
loggedInAt: new Date().toISOString(),
|
||||
};
|
||||
};
|
||||
name: data.name,
|
||||
token: data.token,
|
||||
loggedInAt: new Date().toISOString(),
|
||||
isNewUser: data.isNewUser,
|
||||
};
|
||||
};
|
||||
|
||||
// ─── AuthService ───────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user