create-astratra-app 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +71 -0
  2. package/bin/create-astratra-app.js +9 -0
  3. package/package.json +3 -2
  4. package/src/bricks.js +437 -0
  5. package/src/createProject.js +99 -13
  6. package/templates/mobile/README.md +70 -0
  7. package/templates/mobile/app/_layout.tsx +58 -0
  8. package/templates/mobile/app/dashboard.tsx +73 -0
  9. package/templates/mobile/app/forgot-password.tsx +64 -0
  10. package/templates/mobile/app/home.tsx +32 -0
  11. package/templates/mobile/app/index.tsx +27 -0
  12. package/templates/mobile/app/login.tsx +118 -0
  13. package/templates/mobile/app/notifications.tsx +67 -0
  14. package/templates/mobile/app/onboarding/_layout.tsx +5 -0
  15. package/templates/mobile/app/onboarding/done.tsx +45 -0
  16. package/templates/mobile/app/onboarding/index.tsx +52 -0
  17. package/templates/mobile/app/settings.tsx +95 -0
  18. package/templates/mobile/app.config.js +37 -0
  19. package/templates/mobile/babel.config.js +17 -0
  20. package/templates/mobile/components/AnimatedPressable.tsx +34 -0
  21. package/templates/mobile/components/BrandBackground.tsx +33 -0
  22. package/templates/mobile/components/ErrorBoundary.tsx +28 -0
  23. package/templates/mobile/components/GlassPanel.tsx +67 -0
  24. package/templates/mobile/components/GridBackground.tsx +35 -0
  25. package/templates/mobile/components/KeyboardScreen.tsx +81 -0
  26. package/templates/mobile/components/PasswordEyeIcon.tsx +41 -0
  27. package/templates/mobile/components/SessionGuard.tsx +29 -0
  28. package/templates/mobile/components/dashboard/DashboardHeader.tsx +71 -0
  29. package/templates/mobile/components/dashboard/DashboardReveal.tsx +46 -0
  30. package/templates/mobile/components/dashboard/KpiBubble.tsx +169 -0
  31. package/templates/mobile/components/dashboard/MoreButton.tsx +65 -0
  32. package/templates/mobile/components/dashboard/NotificationBell.tsx +80 -0
  33. package/templates/mobile/components/dashboard/StaffTabBar.tsx +70 -0
  34. package/templates/mobile/components/dashboard/ToolCard.tsx +136 -0
  35. package/templates/mobile/components/glass/LiquidGlassSurface.tsx +266 -0
  36. package/templates/mobile/components/onboarding/StepScreen.tsx +185 -0
  37. package/templates/mobile/constants/dashboard.ts +50 -0
  38. package/templates/mobile/constants/theme.ts +104 -0
  39. package/templates/mobile/context/AuthContext.tsx +106 -0
  40. package/templates/mobile/eas.json +9 -0
  41. package/templates/mobile/env.example +2 -0
  42. package/templates/mobile/features/routes.ts +23 -0
  43. package/templates/mobile/gitignore +7 -0
  44. package/templates/mobile/i18n/config.ts +24 -0
  45. package/templates/mobile/i18n/locales/en.json +62 -0
  46. package/templates/mobile/i18n/locales/fr.json +62 -0
  47. package/templates/mobile/package.json +48 -0
  48. package/templates/mobile/services/push.ts +67 -0
  49. package/templates/mobile/services/session.ts +77 -0
  50. package/templates/mobile/tsconfig.json +8 -0
@@ -1,7 +1,48 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { BRICK_NAMES, brickDependencies, brickFiles, resolveBricks } from './bricks.js';
5
+
6
+ const VALID_TEMPLATES = new Set(['api', 'fullstack', 'mobile']);
7
+
8
+ /* The mobile template is a real Expo file tree, copied as-is.
9
+ Writing an Expo app as inline JS strings — the method the API and web
10
+ templates use — would add well over a thousand lines of quoted TSX to this
11
+ file, unreadable and impossible to lint as what it is. */
12
+ const TEMPLATES_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'templates');
13
+
14
+ /* npm strips a .gitignore from a published tarball, and a .env.example is easy
15
+ to lose the same way. They ship under neutral names and are restored here. */
16
+ const TEMPLATE_RENAMES = new Map([
17
+ ['gitignore', '.gitignore'],
18
+ ['env.example', '.env.example']
19
+ ]);
20
+
21
+ function copyTemplate(templateName, targetDir, projectName) {
22
+ const source = path.join(TEMPLATES_DIR, templateName);
23
+ if (!fs.existsSync(source)) throw new Error(`Template files are missing: ${source}`);
24
+
25
+ const walk = (from, to) => {
26
+ fs.mkdirSync(to, { recursive: true });
27
+ for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
28
+ const renamed = TEMPLATE_RENAMES.get(entry.name) || entry.name;
29
+ const fromPath = path.join(from, entry.name);
30
+ const toPath = path.join(to, renamed);
31
+ if (entry.isDirectory()) {
32
+ walk(fromPath, toPath);
33
+ continue;
34
+ }
35
+ let contents = fs.readFileSync(fromPath, 'utf8');
36
+ if (entry.name === 'package.json') {
37
+ contents = contents.replace('"name": "astratra-mobile-app"', `"name": "${toPackageName(projectName)}"`);
38
+ }
39
+ contents = contents.replaceAll('__PROJECT_NAME__', projectName);
40
+ fs.writeFileSync(toPath, contents);
41
+ }
42
+ };
3
43
 
4
- const VALID_TEMPLATES = new Set(['api', 'fullstack']);
44
+ walk(source, targetDir);
45
+ }
5
46
 
6
47
  function toPackageName(projectName) {
7
48
  return projectName
@@ -25,12 +66,12 @@ function assertCanCreate(targetDir, force) {
25
66
  }
26
67
  }
27
68
 
28
- function packageJson(projectName, template) {
69
+ function packageJson(projectName, template, bricks = []) {
29
70
  const dependencies = {
30
- '@astratra/ai': '^1.0.0',
31
- '@astratra/core': '^1.0.0',
32
- '@astratra/saas-kit': '^1.3.0',
33
- '@astratra/security': '^1.3.0'
71
+ '@astratra/ai': '^1.2.0',
72
+ '@astratra/core': '^1.0.1',
73
+ '@astratra/saas-kit': '^1.6.0',
74
+ '@astratra/security': '^1.10.0'
34
75
  };
35
76
  // Scaffolded (api/stores/mongo.js, api/db/mongo.js) but not wired into
36
77
  // api/server.js by default — the project starts on the in-memory store.
@@ -38,19 +79,24 @@ function packageJson(projectName, template) {
38
79
  // real driver dependency) before the project has ever chosen to use it.
39
80
  // `npm install @astratra/store-mongo mongoose` to switch to MongoDB.
40
81
  const optionalDependencies = {
41
- '@astratra/store-mongo': '^1.0.1',
82
+ '@astratra/store-mongo': '^1.1.0',
42
83
  mongoose: '^8.17.0'
43
84
  };
44
85
  const devDependencies = {};
45
86
 
46
87
  if (template === 'fullstack') {
47
- dependencies['@astratra/saas-kit-ui'] = '^1.0.0';
88
+ dependencies['@astratra/saas-kit-ui'] = '^1.0.1';
48
89
  dependencies.react = '^19.0.0';
49
90
  dependencies['react-dom'] = '^19.0.0';
50
91
  devDependencies['@vitejs/plugin-react'] = '^4.3.4';
51
92
  devDependencies.vite = '^7.0.0';
52
93
  }
53
94
 
95
+ // Les briques demandées s'ajoutent aux dépendances. Rien n'est ajouté sans
96
+ // qu'on l'ait demandé : la plupart de ces packages n'ont aucune dépendance
97
+ // précisément pour qu'on n'en prenne que ce dont on a besoin.
98
+ Object.assign(dependencies, brickDependencies(bricks));
99
+
54
100
  return JSON.stringify({
55
101
  name: toPackageName(projectName),
56
102
  version: '0.1.0',
@@ -595,7 +641,8 @@ export function parseArgs(args) {
595
641
  const options = {
596
642
  targetDir: null,
597
643
  template: 'fullstack',
598
- force: false
644
+ force: false,
645
+ bricks: []
599
646
  };
600
647
 
601
648
  for (let index = 0; index < args.length; index += 1) {
@@ -607,6 +654,11 @@ export function parseArgs(args) {
607
654
  index += 1;
608
655
  } else if (arg.startsWith('--template=')) {
609
656
  options.template = arg.slice('--template='.length);
657
+ } else if (arg === '--with') {
658
+ options.bricks.push(...String(args[index + 1] || '').split(','));
659
+ index += 1;
660
+ } else if (arg.startsWith('--with=')) {
661
+ options.bricks.push(...arg.slice('--with='.length).split(','));
610
662
  } else if (!options.targetDir) {
611
663
  options.targetDir = arg;
612
664
  } else {
@@ -615,23 +667,49 @@ export function parseArgs(args) {
615
667
  }
616
668
 
617
669
  if (!options.targetDir) {
618
- throw new Error('Usage: create-astratra-app <directory> [--template api|fullstack] [--force]');
670
+ throw new Error(
671
+ 'Usage: create-astratra-app <directory> [--template api|fullstack|mobile] ' +
672
+ `[--with ${BRICK_NAMES.slice(0, 3).join(',')},...|all] [--force]`
673
+ );
619
674
  }
620
675
  if (!VALID_TEMPLATES.has(options.template)) {
621
- throw new Error(`Unknown template "${options.template}". Use api or fullstack.`);
676
+ throw new Error(`Unknown template "${options.template}". Use api, fullstack or mobile.`);
622
677
  }
623
678
 
679
+ // Les briques sont du câblage serveur : elles n'ont rien à faire dans une
680
+ // application mobile, et l'accepter en silence livrerait des fichiers morts.
681
+ if (options.template === 'mobile' && options.bricks.length > 0) {
682
+ throw new Error('The mobile template takes no bricks — they are server-side wiring.');
683
+ }
684
+
685
+ // Résolu ici plutôt qu'à l'écriture : un nom de brique fautif doit échouer
686
+ // AVANT que le moindre fichier soit créé.
687
+ options.bricks = resolveBricks(options.bricks, options.template);
688
+
624
689
  return options;
625
690
  }
626
691
 
627
- export function createProject({ targetDir, template = 'fullstack', force = false }, cwd = process.cwd()) {
692
+ export function createProject({ targetDir, template = 'fullstack', force = false, bricks = [] }, cwd = process.cwd()) {
628
693
  const absoluteTarget = path.resolve(cwd, targetDir);
629
694
  const projectName = path.basename(absoluteTarget);
630
695
 
631
696
  assertCanCreate(absoluteTarget, force);
632
697
  fs.mkdirSync(absoluteTarget, { recursive: true });
633
698
 
634
- writeFile(absoluteTarget, 'package.json', `${packageJson(projectName, template)}\n`);
699
+ /* The mobile template shares nothing with the API one: no Express server, no
700
+ Vite, no bricks — those are server-side wiring. */
701
+ if (template === 'mobile') {
702
+ copyTemplate('mobile', absoluteTarget, projectName);
703
+ return {
704
+ targetDir: absoluteTarget,
705
+ bricks: [],
706
+ nextSteps: [`cd ${targetDir}`, 'npm install', 'cp .env.example .env', 'npm start']
707
+ };
708
+ }
709
+
710
+ const selectedBricks = resolveBricks(bricks, template);
711
+
712
+ writeFile(absoluteTarget, 'package.json', `${packageJson(projectName, template, selectedBricks)}\n`);
635
713
  writeFile(absoluteTarget, 'api/server.js', apiServer());
636
714
  writeFile(absoluteTarget, 'api/config/env.js', envConfig());
637
715
  writeFile(absoluteTarget, 'api/security/auth.js', securityAuth());
@@ -657,8 +735,16 @@ export function createProject({ targetDir, template = 'fullstack', force = false
657
735
  writeFile(absoluteTarget, 'web/src/main.jsx', webMain());
658
736
  }
659
737
 
738
+ // Un fichier d'exemple par brique, câblé pour CE projet — pas un extrait de
739
+ // README à recopier. Rien n'est branché dans server.js : une application
740
+ // fraîchement générée doit démarrer sans configuration.
741
+ for (const brick of brickFiles(selectedBricks)) {
742
+ writeFile(absoluteTarget, brick.path, brick.contents);
743
+ }
744
+
660
745
  return {
661
746
  targetDir: absoluteTarget,
747
+ bricks: selectedBricks,
662
748
  nextSteps: [
663
749
  `cd ${targetDir}`,
664
750
  'npm install',
@@ -0,0 +1,70 @@
1
+ # __PROJECT_NAME__
2
+
3
+ Application mobile Expo, montée sur `@astratra/native` et `@astratra/client`.
4
+
5
+ ## Démarrer
6
+
7
+ ```bash
8
+ npm install
9
+ cp .env.example .env
10
+ npm start
11
+ ```
12
+
13
+ L'URL de l'API a une valeur de développement par défaut : `localhost:3000/api`
14
+ sur simulateur iOS, `10.0.2.2:3000` sur émulateur Android — celui-ci tourne
15
+ dans sa propre VM réseau, où « localhost » désigne l'émulateur lui-même.
16
+
17
+ ## Ce qui est déjà là
18
+
19
+ | Fichier | Rôle |
20
+ |---|---|
21
+ | `services/session.ts` | trousseau, jetons, rafraîchissement à vol unique, langue par appel |
22
+ | `services/push.ts` | notifications natives : canaux, catégories, enregistrement de l'appareil |
23
+ | `features/routes.ts` | ce qui est public, et où une notification a le droit de mener |
24
+ | `context/AuthContext.tsx` | qui est connecté, restauration au lancement, déconnexion propre |
25
+ | `components/SessionGuard.tsx` | la pile fermée derrière la session |
26
+ | `app/` | splash, accueil public, connexion, mot de passe oublié, tableau de bord, réglages, notifications |
27
+ | `components/KeyboardScreen.tsx` | l'écran qui survit au clavier — enveloppe tout formulaire |
28
+ | `components/glass/` | la surface de verre : flou natif iOS, réfraction Skia, repli ailleurs |
29
+ | `components/dashboard/` | en-tête, cloche, bandeau de KPI, tuiles, barre d'onglets, apparition en cascade |
30
+ | `constants/dashboard.ts` | ce que le tableau de bord affiche, **en données** — c'est ce qu'on édite pour changer d'application |
31
+
32
+ ## Le clavier
33
+
34
+ Tout écran portant un formulaire s'enveloppe dans `KeyboardScreen`. Ne recopiez
35
+ pas un `KeyboardAvoidingView` à la main : Expo règle Android en
36
+ `softwareKeyboardLayoutMode: 'resize'`, donc le système redimensionne déjà la
37
+ fenêtre. Ajouter `behavior="height"` par-dessus corrige deux fois la même chose
38
+ et fait sauter la mise en page. iOS, lui, ne redimensionne pas et a besoin de
39
+ `padding`. `KeyboardScreen` tranche une fois pour toutes.
40
+
41
+ ## Un *development build*, pas Expo Go
42
+
43
+ L'application démarre dans Expo Go pour un aperçu rapide, mais deux choses n'y
44
+ fonctionnent pas :
45
+
46
+ - **les notifications push** — retirées d'Expo Go depuis le SDK 53 ;
47
+ - **l'effet de verre** — Skia et `expo-glass-effect` sont des modules natifs.
48
+
49
+ ```bash
50
+ npx expo run:ios # ou run:android
51
+ ```
52
+
53
+ C'est de toute façon ce dont a besoin une vraie application livrée à un client.
54
+
55
+ ## Ce qu'il faut changer en premier
56
+
57
+ 1. `app.config.js` — nom, slug, `scheme`, identifiants iOS/Android.
58
+ 2. `features/routes.ts` — les écrans publics et les routes de notification de
59
+ VOTRE application. Les deux listes nomment ce qui est **autorisé** : un
60
+ écran ajouté plus tard et oublié reste fermé, ce qui est le bon défaut.
61
+ 3. `services/push.ts` — les canaux Android et les points d'API qui
62
+ enregistrent un appareil.
63
+ 4. `constants/theme.ts` — couleurs et espacements.
64
+ 5. `i18n/locales/` — les textes.
65
+
66
+ ## Ce qui n'est pas fourni
67
+
68
+ Le métier. Les écrans livrés sont le socle qu'aucune application ne réécrit :
69
+ se connecter, rester connecté, être notifié, se déconnecter. Ce qui distingue
70
+ votre application se construit par-dessus.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The shell every screen sits in: session, guard, notifications, language.
3
+ *
4
+ * The order matters. The guard must be INSIDE the auth provider — it needs to
5
+ * know whether the session is still restoring — and the notification listeners
6
+ * must start after both, because where a tapped notification leads depends on
7
+ * who is signed in.
8
+ */
9
+ import { useEffect } from 'react';
10
+ import Constants, { ExecutionEnvironment } from 'expo-constants';
11
+ import { Stack } from 'expo-router';
12
+ import { StatusBar } from 'expo-status-bar';
13
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
14
+ import { AuthProvider, useAuth } from '../context/AuthContext';
15
+ import { SessionGuard } from '../components/SessionGuard';
16
+ import { ErrorBoundary } from '../components/ErrorBoundary';
17
+ import { push } from '../services/push';
18
+ import '../i18n/config';
19
+
20
+ /**
21
+ * Expo Go cannot receive push notifications — remote push was removed from it
22
+ * in SDK 53 — and merely touching the module there raises a red error banner
23
+ * over a perfectly healthy app. Starting the listeners is skipped, rather than
24
+ * attempted and failed noisily.
25
+ *
26
+ * Nothing else changes: in a development build, and in the shipped app, this
27
+ * is false and the listeners start normally.
28
+ */
29
+ const IN_EXPO_GO = Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
30
+
31
+ function NotificationBridge() {
32
+ const { user } = useAuth();
33
+
34
+ useEffect(() => {
35
+ if (!user || IN_EXPO_GO) return undefined;
36
+ let stop: (() => void) | undefined;
37
+ void push.startListeners(user.role).then((dispose) => { stop = dispose; });
38
+ return () => { if (stop) stop(); };
39
+ }, [user]);
40
+
41
+ return null;
42
+ }
43
+
44
+ export default function RootLayout() {
45
+ return (
46
+ <SafeAreaProvider>
47
+ <ErrorBoundary>
48
+ <AuthProvider>
49
+ <SessionGuard>
50
+ <NotificationBridge />
51
+ <StatusBar style="light" />
52
+ <Stack screenOptions={{ headerShown: false, animation: 'fade' }} />
53
+ </SessionGuard>
54
+ </AuthProvider>
55
+ </ErrorBoundary>
56
+ </SafeAreaProvider>
57
+ );
58
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The dashboard, built from the real components.
3
+ *
4
+ * Everything on this screen is DATA, not markup: the KPI row and the tiles are
5
+ * declared as lists, so a product changes what its dashboard shows by editing
6
+ * `constants/dashboard.ts` — not by rewriting a screen. That is what lets one
7
+ * dashboard serve several roles.
8
+ */
9
+ import { useMemo } from 'react';
10
+ import { ScrollView, View } from 'react-native';
11
+ import { useRouter } from 'expo-router';
12
+ import { useTranslation } from 'react-i18next';
13
+ import DashboardHeader from '../components/dashboard/DashboardHeader';
14
+ import DashboardReveal from '../components/dashboard/DashboardReveal';
15
+ import KpiBubble from '../components/dashboard/KpiBubble';
16
+ import MoreButton from '../components/dashboard/MoreButton';
17
+ import StaffTabBar from '../components/dashboard/StaffTabBar';
18
+ import ToolCard from '../components/dashboard/ToolCard';
19
+ import { useAuth } from '../context/AuthContext';
20
+ import { colors, spacing } from '../constants/theme';
21
+ import GridBackground from '../components/GridBackground';
22
+ import { dashboardKpis, dashboardTabs, dashboardTools } from '../constants/dashboard';
23
+
24
+ export default function Dashboard() {
25
+ const { t } = useTranslation();
26
+ const { user } = useAuth();
27
+ const router = useRouter();
28
+
29
+ const kpis = useMemo(() => dashboardKpis(t), [t]);
30
+ const tools = useMemo(() => dashboardTools(t), [t]);
31
+ const tabs = useMemo(() => dashboardTabs(t), [t]);
32
+
33
+ return (
34
+ <View style={{ flex: 1, backgroundColor: colors.background }}>
35
+ <GridBackground />
36
+ {/* Room at the bottom for the tab bar, which floats over the content. */}
37
+ <ScrollView contentContainerStyle={{ padding: spacing.lg, paddingTop: spacing.xl * 2, paddingBottom: 120 }}>
38
+ <DashboardHeader name={user?.fullName || user?.email || ''} online unread={0} />
39
+
40
+ <DashboardReveal delay={60}>
41
+ <View style={{ marginTop: spacing.lg }}>
42
+ <KpiBubble items={kpis} />
43
+ </View>
44
+ </DashboardReveal>
45
+
46
+ <View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 12, marginTop: spacing.lg }}>
47
+ {tools.map((tool, index) => (
48
+ <DashboardReveal key={tool.label} delay={120 + index * 60}>
49
+ <ToolCard
50
+ card={tool}
51
+ index={index}
52
+ gridPadding={spacing.lg * 2}
53
+ onPress={() => tool.path && router.push(tool.path as never)}
54
+ />
55
+ </DashboardReveal>
56
+ ))}
57
+ </View>
58
+
59
+ <MoreButton
60
+ label={t('dashboard.see_all')}
61
+ delay={120 + tools.length * 60}
62
+ onPress={() => router.push('/settings' as never)}
63
+ />
64
+ </ScrollView>
65
+
66
+ <StaffTabBar
67
+ tabs={tabs}
68
+ activeKey="home"
69
+ onSelect={(tab) => tab.path && router.push(tab.path as never)}
70
+ />
71
+ </View>
72
+ );
73
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Asking for a reset link.
3
+ *
4
+ * The answer is deliberately the same whether the address exists or not: a
5
+ * screen that says "unknown address" is an account-enumeration oracle.
6
+ */
7
+ import { useState } from 'react';
8
+ import { Text, TextInput } from 'react-native';
9
+ import { useTranslation } from 'react-i18next';
10
+ import { api } from '../services/session';
11
+ import { AnimatedPressable } from '../components/AnimatedPressable';
12
+ import { GlassPanel } from '../components/GlassPanel';
13
+ import { KeyboardScreen } from '../components/KeyboardScreen';
14
+ import GridBackground from '../components/GridBackground';
15
+ import { colors, fontWeights, spacing } from '../constants/theme';
16
+
17
+ export default function ForgotPassword() {
18
+ const { t } = useTranslation();
19
+ const [email, setEmail] = useState('');
20
+ const [sent, setSent] = useState(false);
21
+
22
+ const submit = async () => {
23
+ try {
24
+ await api.request('/auth/forgot-password', { method: 'POST', body: JSON.stringify({ email: email.trim() }) });
25
+ } catch {
26
+ /* same answer either way */
27
+ }
28
+ setSent(true);
29
+ };
30
+
31
+ return (
32
+ <KeyboardScreen background={<GridBackground />} contentStyle={{ justifyContent: 'center', padding: spacing.lg }}>
33
+ <GlassPanel>
34
+ <Text style={{ color: colors.text, fontSize: 22, fontWeight: fontWeights.bold }}>{t('auth.forgot')}</Text>
35
+ <TextInput
36
+ style={{
37
+ color: colors.text,
38
+ backgroundColor: colors.surface,
39
+ borderColor: colors.border,
40
+ borderWidth: 1,
41
+ borderRadius: 14,
42
+ padding: spacing.md,
43
+ marginTop: spacing.md
44
+ }}
45
+ placeholder={t('auth.email')}
46
+ placeholderTextColor={colors.muted}
47
+ autoCapitalize="none"
48
+ keyboardType="email-address"
49
+ value={email}
50
+ onChangeText={setEmail}
51
+ />
52
+ {sent && <Text style={{ color: colors.muted, marginTop: spacing.sm }}>{t('auth.reset_sent')}</Text>}
53
+ <AnimatedPressable
54
+ onPress={submit}
55
+ style={{ marginTop: spacing.lg, backgroundColor: colors.accent, borderRadius: 14, padding: spacing.md }}
56
+ >
57
+ <Text style={{ color: colors.onAccent, textAlign: 'center', fontWeight: fontWeights.semibold }}>
58
+ {t('auth.send_link')}
59
+ </Text>
60
+ </AnimatedPressable>
61
+ </GlassPanel>
62
+ </KeyboardScreen>
63
+ );
64
+ }
@@ -0,0 +1,32 @@
1
+ import { Text, View } from 'react-native';
2
+ import { useRouter } from 'expo-router';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { AnimatedPressable } from '../components/AnimatedPressable';
5
+ import { GlassPanel } from '../components/GlassPanel';
6
+ import GridBackground from '../components/GridBackground';
7
+ import { colors, fontWeights, spacing } from '../constants/theme';
8
+
9
+ export default function Home() {
10
+ const { t } = useTranslation();
11
+ const router = useRouter();
12
+
13
+ return (
14
+ <View style={{ flex: 1, backgroundColor: colors.background }}>
15
+ <GridBackground />
16
+ <View style={{ flex: 1, justifyContent: 'center', padding: spacing.lg }}>
17
+ <GlassPanel>
18
+ <Text style={{ color: colors.text, fontSize: 28, fontWeight: fontWeights.bold }}>{t('home.welcome')}</Text>
19
+ <Text style={{ color: colors.muted, marginTop: spacing.sm }}>{t('app.name')}</Text>
20
+ <AnimatedPressable
21
+ onPress={() => router.push('/login')}
22
+ style={{ marginTop: spacing.lg, backgroundColor: colors.accent, borderRadius: 14, padding: spacing.md }}
23
+ >
24
+ <Text style={{ color: colors.onAccent, textAlign: 'center', fontWeight: fontWeights.semibold }}>
25
+ {t('home.start')}
26
+ </Text>
27
+ </AnimatedPressable>
28
+ </GlassPanel>
29
+ </View>
30
+ </View>
31
+ );
32
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The splash: it decides where to go, so the guard does not have to.
3
+ *
4
+ * While the session restores, nothing is decided. Redirecting on the transient
5
+ * state is what makes the sign-in screen flash at every cold start.
6
+ */
7
+ import { useEffect } from 'react';
8
+ import { ActivityIndicator, View } from 'react-native';
9
+ import { useRouter } from 'expo-router';
10
+ import { useAuth } from '../context/AuthContext';
11
+ import { colors } from '../constants/theme';
12
+
13
+ export default function Splash() {
14
+ const { user, loading } = useAuth();
15
+ const router = useRouter();
16
+
17
+ useEffect(() => {
18
+ if (loading) return;
19
+ router.replace(user ? '/dashboard' : '/home');
20
+ }, [user, loading, router]);
21
+
22
+ return (
23
+ <View style={{ flex: 1, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }}>
24
+ <ActivityIndicator color={colors.accent} />
25
+ </View>
26
+ );
27
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Signing in.
3
+ *
4
+ * The password rules come from @astratra/client and are the SAME object the
5
+ * server validates against — a rule duplicated with a drift is a password
6
+ * accepted on screen and refused on submit.
7
+ */
8
+ import { useState } from 'react';
9
+ import { ActivityIndicator, Pressable, Text, TextInput, View } from 'react-native';
10
+ import { useTranslation } from 'react-i18next';
11
+ import { useRouter } from 'expo-router';
12
+ import { createPasswordRules } from '@astratra/client';
13
+ import { useAuth } from '../context/AuthContext';
14
+ import { AnimatedPressable } from '../components/AnimatedPressable';
15
+ import { GlassPanel } from '../components/GlassPanel';
16
+ import { KeyboardScreen } from '../components/KeyboardScreen';
17
+ import GridBackground from '../components/GridBackground';
18
+ import PasswordEyeIcon from '../components/PasswordEyeIcon';
19
+ import { colors, fontWeights, spacing } from '../constants/theme';
20
+
21
+ const rules = createPasswordRules();
22
+
23
+ export default function Login() {
24
+ const { t } = useTranslation();
25
+ const { signIn } = useAuth();
26
+ const router = useRouter();
27
+ const [email, setEmail] = useState('');
28
+ const [password, setPassword] = useState('');
29
+ const [busy, setBusy] = useState(false);
30
+ const [revealed, setRevealed] = useState(false);
31
+ const [failed, setFailed] = useState(false);
32
+
33
+ const submit = async () => {
34
+ setFailed(false);
35
+ setBusy(true);
36
+ try {
37
+ await signIn(email.trim(), password);
38
+ router.replace('/dashboard');
39
+ } catch {
40
+ setFailed(true);
41
+ } finally {
42
+ setBusy(false);
43
+ }
44
+ };
45
+
46
+ const input = {
47
+ color: colors.text,
48
+ backgroundColor: colors.surface,
49
+ borderColor: colors.border,
50
+ borderWidth: 1,
51
+ borderRadius: 14,
52
+ padding: spacing.md,
53
+ marginTop: spacing.sm
54
+ };
55
+
56
+ return (
57
+ <KeyboardScreen background={<GridBackground />} contentStyle={{ justifyContent: 'center', padding: spacing.lg }}>
58
+ <GlassPanel>
59
+ <Text style={{ color: colors.text, fontSize: 24, fontWeight: fontWeights.bold }}>{t('auth.sign_in')}</Text>
60
+
61
+ <TextInput
62
+ style={input}
63
+ placeholder={t('auth.email')}
64
+ placeholderTextColor={colors.muted}
65
+ autoCapitalize="none"
66
+ keyboardType="email-address"
67
+ value={email}
68
+ onChangeText={setEmail}
69
+ />
70
+ <View>
71
+ <TextInput
72
+ style={[input, { paddingRight: spacing.xl + spacing.md }]}
73
+ placeholder={t('auth.password')}
74
+ placeholderTextColor={colors.muted}
75
+ secureTextEntry={!revealed}
76
+ value={password}
77
+ onChangeText={setPassword}
78
+ />
79
+ <Pressable
80
+ accessibilityRole="button"
81
+ accessibilityLabel={t(revealed ? 'auth.hide_password' : 'auth.show_password')}
82
+ onPress={() => setRevealed((shown) => !shown)}
83
+ /* A bigger touch area than the glyph: an 18px icon is below every
84
+ platform's minimum target and is missed as often as it is hit. */
85
+ hitSlop={12}
86
+ style={{ position: 'absolute', right: spacing.md, top: 0, bottom: 0, justifyContent: 'center' }}
87
+ >
88
+ <PasswordEyeIcon visible={revealed} />
89
+ </Pressable>
90
+ </View>
91
+
92
+ {/* Each condition separately, so the person sees WHICH one is missing
93
+ while typing — not a single line they discover they failed on submit. */}
94
+ {password.length > 0 && rules.check(password).map((rule) => (
95
+ <Text key={rule.key} style={{ color: rule.met ? colors.accent : colors.muted, marginTop: spacing.xs }}>
96
+ {rule.met ? '✓' : '·'} {t(`password.${rule.key}`)}
97
+ </Text>
98
+ ))}
99
+
100
+ {failed && <Text style={{ color: colors.danger, marginTop: spacing.sm }}>{t('auth.failed')}</Text>}
101
+
102
+ <AnimatedPressable
103
+ onPress={submit}
104
+ disabled={busy}
105
+ style={{ marginTop: spacing.lg, backgroundColor: colors.accent, borderRadius: 14, padding: spacing.md }}
106
+ >
107
+ {busy
108
+ ? <ActivityIndicator color={colors.onAccent} />
109
+ : <Text style={{ color: colors.onAccent, textAlign: 'center', fontWeight: fontWeights.semibold }}>{t('auth.sign_in')}</Text>}
110
+ </AnimatedPressable>
111
+
112
+ <AnimatedPressable onPress={() => router.push('/forgot-password')} style={{ marginTop: spacing.md }}>
113
+ <Text style={{ color: colors.muted, textAlign: 'center' }}>{t('auth.forgot')}</Text>
114
+ </AnimatedPressable>
115
+ </GlassPanel>
116
+ </KeyboardScreen>
117
+ );
118
+ }