infra: add linting and formatting for js projects (#230)
* wip * wip * wip * format * wip(mobile): lint and format * cleanup * nits * nits * idiomatic react * nit * format all root files
This commit was merged in pull request #230.
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import * as SecureStore from "expo-secure-store";
|
||||
import { create } from "zustand";
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import { create } from 'zustand';
|
||||
import {
|
||||
signInWithCustomToken,
|
||||
signOut as firebaseSignOut,
|
||||
} from "firebase/auth";
|
||||
import { apiClient } from "@/api/client";
|
||||
import type { Human } from "@/api/types";
|
||||
import { firebaseAuth } from "@/firebase";
|
||||
import { logError, ApiError } from "@/lib/errors";
|
||||
} from 'firebase/auth';
|
||||
import { apiClient } from '@/api/client';
|
||||
import type { Human } from '@/api/types';
|
||||
import { firebaseAuth } from '@/firebase';
|
||||
import { logError, ApiError } from '@/lib/errors';
|
||||
import {
|
||||
startPushTokenSync,
|
||||
stopPushTokenSync,
|
||||
syncPushToken,
|
||||
unregisterPushToken,
|
||||
} from "@/lib/push-notifications";
|
||||
} from '@/lib/push-notifications';
|
||||
|
||||
const AUTH_TOKEN_KEY = "auth_token";
|
||||
const AUTH_TOKEN_KEY = 'auth_token';
|
||||
|
||||
async function readPersistedToken(): Promise<string | null> {
|
||||
try {
|
||||
@@ -45,11 +45,11 @@ async function signInToFirebase(): Promise<void> {
|
||||
} catch (err) {
|
||||
// Firestore subscriptions will fail until the next successful sign-in; the
|
||||
// rest of the app keeps working against Orion. Sentry catches the failure.
|
||||
logError(err, { scope: "auth.firebase" });
|
||||
logError(err, { scope: 'auth.firebase' });
|
||||
}
|
||||
}
|
||||
|
||||
type AuthStatus = "idle" | "restoring" | "unauthenticated" | "authenticated";
|
||||
type AuthStatus = 'idle' | 'restoring' | 'unauthenticated' | 'authenticated';
|
||||
|
||||
interface AuthState {
|
||||
status: AuthStatus;
|
||||
@@ -73,7 +73,7 @@ interface AuthState {
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
status: "idle",
|
||||
status: 'idle',
|
||||
user: null,
|
||||
token: null,
|
||||
isRequestingCode: false,
|
||||
@@ -82,11 +82,11 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
error: null,
|
||||
|
||||
restoreSession: async () => {
|
||||
set({ status: "restoring" });
|
||||
set({ status: 'restoring' });
|
||||
|
||||
const token = await readPersistedToken();
|
||||
if (!token) {
|
||||
set({ status: "unauthenticated" });
|
||||
set({ status: 'unauthenticated' });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
try {
|
||||
const user = await apiClient.me();
|
||||
await signInToFirebase();
|
||||
set({ status: "authenticated", user });
|
||||
set({ status: 'authenticated', user });
|
||||
startPushTokenSync();
|
||||
void syncPushToken();
|
||||
} catch (err) {
|
||||
// Expected on expired/invalid tokens — fall back to the login screen.
|
||||
logError(err, { scope: "auth.restore" });
|
||||
logError(err, { scope: 'auth.restore' });
|
||||
await get().invalidateSession();
|
||||
}
|
||||
},
|
||||
@@ -111,8 +111,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
try {
|
||||
await apiClient.requestCode({ email });
|
||||
} catch (e) {
|
||||
const message =
|
||||
e instanceof ApiError ? e.message : "Failed to send code";
|
||||
const message = e instanceof ApiError ? e.message : 'Failed to send code';
|
||||
set({ error: message });
|
||||
throw e;
|
||||
} finally {
|
||||
@@ -128,11 +127,11 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
apiClient.setToken(token);
|
||||
set({ token });
|
||||
await signInToFirebase();
|
||||
set({ status: "authenticated", user: human });
|
||||
set({ status: 'authenticated', user: human });
|
||||
startPushTokenSync();
|
||||
void syncPushToken();
|
||||
} catch (e) {
|
||||
const message = e instanceof ApiError ? e.message : "Failed to sign in";
|
||||
const message = e instanceof ApiError ? e.message : 'Failed to sign in';
|
||||
set({ error: message });
|
||||
throw e;
|
||||
} finally {
|
||||
@@ -150,15 +149,15 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
await apiClient.signOut();
|
||||
} catch (err) {
|
||||
// Best-effort — sign out locally regardless.
|
||||
logError(err, { scope: "auth.signOut" });
|
||||
logError(err, { scope: 'auth.signOut' });
|
||||
} finally {
|
||||
await firebaseSignOut(firebaseAuth).catch((err) =>
|
||||
logError(err, { scope: "auth.firebaseSignOut" }),
|
||||
logError(err, { scope: 'auth.firebaseSignOut' }),
|
||||
);
|
||||
apiClient.setToken(null);
|
||||
await clearPersistedToken();
|
||||
set({
|
||||
status: "unauthenticated",
|
||||
status: 'unauthenticated',
|
||||
user: null,
|
||||
token: null,
|
||||
isSigningOut: false,
|
||||
@@ -171,7 +170,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
stopPushTokenSync();
|
||||
apiClient.setToken(null);
|
||||
await clearPersistedToken();
|
||||
set({ status: "unauthenticated", user: null, token: null });
|
||||
set({ status: 'unauthenticated', user: null, token: null });
|
||||
|
||||
await unregisterPushToken(); // Best-effort
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { create } from "zustand";
|
||||
import { create } from 'zustand';
|
||||
|
||||
/**
|
||||
* Single source of truth for "is stream playback paused." Each component that
|
||||
|
||||
Reference in New Issue
Block a user