create-disposabl-app 0.4.1 → 0.5.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 (80) hide show
  1. package/README.md +6 -0
  2. package/dist/index.js +68 -57
  3. package/dist/templates/default/apps/docs/README.md +37 -0
  4. package/dist/templates/default/apps/docs/content/guides/writing.mdx +15 -0
  5. package/dist/templates/default/apps/docs/content/index.mdx +10 -0
  6. package/dist/templates/default/apps/docs/package.json +29 -1
  7. package/dist/templates/default/apps/docs/press.config.ts +20 -0
  8. package/dist/templates/default/apps/docs/src/app.css +4 -0
  9. package/dist/templates/default/apps/docs/tsconfig.json +14 -0
  10. package/dist/templates/default/apps/docs/vite.config.ts +8 -0
  11. package/dist/templates/default/apps/mobile/.env.example +2 -0
  12. package/dist/templates/default/apps/mobile/README.md +63 -4
  13. package/dist/templates/default/apps/mobile/app.json +2 -0
  14. package/dist/templates/default/apps/mobile/package.json +16 -3
  15. package/dist/templates/default/apps/mobile/src/app/(auth)/_layout.tsx +1 -0
  16. package/dist/templates/default/apps/mobile/src/app/(auth)/login.tsx +1 -0
  17. package/dist/templates/default/apps/mobile/src/app/(auth)/signup.tsx +1 -0
  18. package/dist/templates/default/apps/mobile/src/app/(authenticated)/_layout.tsx +1 -0
  19. package/dist/templates/default/apps/mobile/src/app/(authenticated)/account.tsx +1 -0
  20. package/dist/templates/default/apps/mobile/src/app/_layout.tsx +1 -5
  21. package/dist/templates/default/apps/mobile/src/app/index.tsx +1 -17
  22. package/dist/templates/default/apps/mobile/tsconfig.json +8 -1
  23. package/dist/templates/default/apps/web/package.json +2 -1
  24. package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.api-keys.tsx +1 -1
  25. package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +2 -0
  26. package/dist/templates/default/apps/web/src/router/_authenticated/todos/$id.tsx +1 -1
  27. package/dist/templates/default/apps/web/src/router/_authenticated/todos/index.tsx +1 -1
  28. package/dist/templates/default/apps/web/tests/auth-branches.test.tsx +44 -0
  29. package/dist/templates/default/apps/web/vite.config.ts +15 -0
  30. package/dist/templates/default/bun.lock +564 -18
  31. package/dist/templates/default/disposabl.json +2 -13
  32. package/dist/templates/default/packages/backend/convex/users.ts +23 -0
  33. package/dist/templates/default/packages/disposabl-kit/client/components/ui/log-out.tsx +16 -0
  34. package/dist/templates/default/packages/disposabl-kit/client/lib/prerender.ts +6 -3
  35. package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/login.tsx +1 -1
  36. package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/signUp.tsx +1 -1
  37. package/dist/templates/default/packages/disposabl-kit/client/routes/_authenticated/route.tsx +25 -16
  38. package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +1 -1
  39. package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +23 -2
  40. package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +20 -9
  41. package/dist/templates/default/packages/disposabl-kit/eslint.config.js +1 -1
  42. package/dist/templates/default/packages/disposabl-kit/features.ts +4 -0
  43. package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-form.tsx +125 -0
  44. package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-ui.tsx +107 -0
  45. package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +26 -0
  46. package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +10 -0
  47. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +101 -0
  48. package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-errors.ts +40 -0
  49. package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-storage.ts +9 -0
  50. package/dist/templates/default/packages/disposabl-kit/mobile/lib/convex.ts +1 -0
  51. package/dist/templates/default/packages/disposabl-kit/mobile/screens/account.tsx +67 -0
  52. package/dist/templates/default/packages/disposabl-kit/mobile/screens/home.tsx +50 -0
  53. package/dist/templates/default/packages/disposabl-kit/mobile/screens/login.tsx +5 -0
  54. package/dist/templates/default/packages/disposabl-kit/mobile/screens/signup.tsx +5 -0
  55. package/dist/templates/default/packages/disposabl-kit/package.json +24 -1
  56. package/dist/templates/default/packages/disposabl-kit/platforms.ts +1 -27
  57. package/dist/templates/default/packages/disposabl-kit/server/http.ts +6 -0
  58. package/dist/templates/default/packages/disposabl-kit/server/lib/docs.test.ts +111 -0
  59. package/dist/templates/default/packages/disposabl-kit/server/lib/docs.ts +62 -0
  60. package/dist/templates/default/packages/disposabl-kit/tsconfig.json +1 -1
  61. package/dist/templates/default/turbo.json +7 -0
  62. package/package.json +1 -1
  63. package/dist/templates/default/apps/blog/package.json +0 -1
  64. package/dist/templates/default/apps/changelog/package.json +0 -1
  65. package/dist/templates/default/apps/desktop/.oxfmtrc.json +0 -5
  66. package/dist/templates/default/apps/desktop/.oxlintrc.json +0 -6
  67. package/dist/templates/default/apps/desktop/README.md +0 -88
  68. package/dist/templates/default/apps/desktop/build-ci.mjs +0 -56
  69. package/dist/templates/default/apps/desktop/forge.config.mts +0 -109
  70. package/dist/templates/default/apps/desktop/index.html +0 -12
  71. package/dist/templates/default/apps/desktop/package.json +0 -55
  72. package/dist/templates/default/apps/desktop/src/declarations.d.ts +0 -2
  73. package/dist/templates/default/apps/desktop/src/index.css +0 -8
  74. package/dist/templates/default/apps/desktop/src/main.ts +0 -58
  75. package/dist/templates/default/apps/desktop/src/preload.ts +0 -3
  76. package/dist/templates/default/apps/desktop/src/renderer.ts +0 -19
  77. package/dist/templates/default/apps/desktop/tsconfig.json +0 -14
  78. package/dist/templates/default/apps/desktop/vite.main.config.mts +0 -4
  79. package/dist/templates/default/apps/desktop/vite.preload.config.mts +0 -4
  80. package/dist/templates/default/apps/desktop/vite.renderer.config.mts +0 -4
@@ -1,16 +1,5 @@
1
1
  {
2
2
  "version": "0.1.0",
3
- "platforms": [
4
- "web",
5
- "android",
6
- "ios",
7
- "windows",
8
- "macos",
9
- "linux",
10
- "api",
11
- "mcp",
12
- "cli",
13
- "typescript-sdk"
14
- ],
15
- "features": ["authentication"]
3
+ "platforms": ["web", "android", "ios", "api", "mcp", "cli", "typescript-sdk"],
4
+ "features": ["authentication", "docs"]
16
5
  }
@@ -1,5 +1,28 @@
1
1
  import { v } from "convex/values";
2
+ import { getAuthUserId } from "@convex-dev/auth/server";
2
3
  import { internalMutation } from "@disposabl/disposabl-kit/server/lib/functions";
4
+ import { components } from "./_generated/api";
5
+ import { query } from "./_generated/server";
6
+
7
+ /** Return only the caller's account, using the identity verified by Convex. */
8
+ export const current = query({
9
+ args: {},
10
+ returns: v.union(
11
+ v.null(),
12
+ v.object({ id: v.id("users"), username: v.union(v.string(), v.null()) }),
13
+ ),
14
+ handler: async (ctx) => {
15
+ const userId = await getAuthUserId(ctx);
16
+ if (userId === null || (await ctx.db.get("users", userId)) === null) {
17
+ return null;
18
+ }
19
+ const username = await ctx.runQuery(
20
+ components.authUsername.public.getUsername,
21
+ { userId },
22
+ );
23
+ return { id: userId, username };
24
+ },
25
+ });
3
26
 
4
27
  /**
5
28
  * Create the user row for a new password account and return its id. This
@@ -0,0 +1,16 @@
1
+ import { useAuthActions } from "@convex-dev/auth/react";
2
+
3
+ export function LogOut() {
4
+ const { signOut } = useAuthActions();
5
+ return (
6
+ <button
7
+ type="button"
8
+ onClick={async () => {
9
+ await signOut();
10
+ window.location.assign("/");
11
+ }}
12
+ >
13
+ Log out
14
+ </button>
15
+ );
16
+ }
@@ -81,15 +81,18 @@ export function createPrerenderFilter(
81
81
  let source: string | undefined;
82
82
  let isAuthenticated: ReturnType<typeof routeMatcher> | undefined;
83
83
  return (page: { path: string; sitemap?: { exclude?: boolean } }) => {
84
+ const pathname = new URL(page.path, "http://localhost").pathname;
85
+ // docs:start
86
+ // Fumapress builds its own pages, including links crawled from the web app.
87
+ if (/^\/docs(?:\/|$)/.test(pathname)) return false;
88
+ // docs:end
84
89
  // Read lazily: Start generates the route tree after loading the Vite config.
85
90
  const nextSource = readFileSync(routeTreeFile, "utf8");
86
91
  if (nextSource !== source) {
87
92
  isAuthenticated = routeMatcher(nextSource);
88
93
  source = nextSource;
89
94
  }
90
- const authenticated = isAuthenticated!(
91
- new URL(page.path, "http://localhost").pathname,
92
- );
95
+ const authenticated = isAuthenticated!(pathname);
93
96
  if (authenticated) page.sitemap = { ...page.sitemap, exclude: true };
94
97
  return !authenticated;
95
98
  };
@@ -22,7 +22,7 @@ export function LogIn() {
22
22
  if (result.status === "complete") {
23
23
  if (request)
24
24
  await navigate({ to: "/consent", search: { request } });
25
- else if (returnTo) window.location.assign(returnTo);
25
+ else window.location.assign(returnTo ?? "/dashboard");
26
26
  return;
27
27
  }
28
28
  setError(() => {
@@ -23,7 +23,7 @@ export function SignUp() {
23
23
  if (result.status === "complete") {
24
24
  if (request)
25
25
  await navigate({ to: "/consent", search: { request } });
26
- else if (returnTo) window.location.assign(returnTo);
26
+ else window.location.assign(returnTo ?? "/dashboard");
27
27
  return;
28
28
  }
29
29
  setError(() => {
@@ -6,33 +6,42 @@ import {
6
6
  } from "@tanstack/react-router";
7
7
  import { Authenticated, AuthLoading, Unauthenticated } from "convex/react";
8
8
  import { useState } from "react";
9
+ import { authenticationEnabled } from "../../../features";
9
10
  import { Spinner } from "../../components/ui/spinner";
10
11
 
11
12
  export const Route = createFileRoute("/_providers/_authenticated")({
12
13
  ssr: false,
13
14
  head: () => ({ meta: [{ name: "robots", content: "noindex, nofollow" }] }),
14
- component: function AuthenticatedLayout() {
15
- return (
16
- <>
17
- <Authenticated>
18
- <Outlet />
19
- </Authenticated>
20
- <Unauthenticated>
21
- <SignInRedirect />
22
- </Unauthenticated>
23
- <AuthLoading>
24
- <Spinner className="h-10 w-10 animate-spin" />
25
- </AuthLoading>
26
- </>
27
- );
28
- },
15
+ component: AuthenticatedLayout,
29
16
  });
30
17
 
18
+ export function AuthenticatedLayout({
19
+ enabled = authenticationEnabled,
20
+ }: { enabled?: boolean } = {}) {
21
+ if (!enabled) return <Outlet />;
22
+ return (
23
+ <>
24
+ <Authenticated>
25
+ <Outlet />
26
+ </Authenticated>
27
+ <Unauthenticated>
28
+ <SignInRedirect />
29
+ </Unauthenticated>
30
+ <AuthLoading>
31
+ <Spinner className="h-10 w-10 animate-spin" />
32
+ </AuthLoading>
33
+ </>
34
+ );
35
+ }
36
+
31
37
  function SignInRedirect() {
32
38
  const href = useRouterState({
33
39
  select: (state) => state.location.href,
34
40
  });
35
41
  // Keep the destination stable while navigating away from the protected route.
36
42
  const [returnTo] = useState(href);
37
- return <Navigate to="/login" search={{ returnTo }} />;
43
+ // The login route is intentionally absent from the generated types when auth is disabled.
44
+ return (
45
+ <Navigate from="/" href={`/login?${new URLSearchParams({ returnTo })}`} />
46
+ );
38
47
  }
@@ -14,7 +14,7 @@ export const Route = createFileRoute("/_providers/consent")({
14
14
  component: ConsentPage,
15
15
  });
16
16
 
17
- function ConsentPage() {
17
+ export function ConsentPage() {
18
18
  const { request: requestId } = Route.useSearch();
19
19
  const request = useQuery(
20
20
  api.mcp.getAuthRequest,
@@ -1,7 +1,8 @@
1
1
  import { useState } from "react";
2
2
  import { createFileRoute, Outlet } from "@tanstack/react-router";
3
3
  import { ConvexAuthProvider } from "@convex-dev/auth/react";
4
- import { ConvexReactClient } from "convex/react";
4
+ import { ConvexProvider, ConvexReactClient } from "convex/react";
5
+ import { authenticationEnabled } from "../../features";
5
6
  import { api } from "../../../backend/convex/_generated/api";
6
7
 
7
8
  export const Route = createFileRoute("/_providers")({
@@ -16,6 +17,26 @@ function Providers() {
16
17
  return new ConvexReactClient(url);
17
18
  });
18
19
 
20
+ return (
21
+ <AuthProvider client={client} enabled={authenticationEnabled}>
22
+ <Outlet />
23
+ </AuthProvider>
24
+ );
25
+ }
26
+
27
+ export function AuthProvider({
28
+ client,
29
+ enabled,
30
+ children,
31
+ }: {
32
+ client: ConvexReactClient;
33
+ enabled: boolean;
34
+ children: React.ReactNode;
35
+ }) {
36
+ if (!enabled) {
37
+ return <ConvexProvider client={client}>{children}</ConvexProvider>;
38
+ }
39
+
19
40
  return (
20
41
  <ConvexAuthProvider
21
42
  client={client}
@@ -24,7 +45,7 @@ function Providers() {
24
45
  signOut: api.auth.signOut,
25
46
  }}
26
47
  >
27
- <Outlet />
48
+ {children}
28
49
  </ConvexAuthProvider>
29
50
  );
30
51
  }
@@ -1,4 +1,5 @@
1
1
  import { relative, resolve } from "node:path";
2
+ import { readFileSync } from "node:fs";
2
3
  import { fileURLToPath } from "node:url";
3
4
  import {
4
5
  layout,
@@ -14,15 +15,25 @@ const kitRoute = (file: string) =>
14
15
  );
15
16
 
16
17
  // Both Vite and `tsr generate` use this route tree.
17
- export const routes = rootRoute("__root.tsx", [
18
- layout("_providers", kitRoute("route.tsx"), [
19
- physical("."),
20
- route("/login", kitRoute("_auth-pages/login.tsx")),
21
- route("/signup", kitRoute("_auth-pages/signUp.tsx")),
22
- route("/consent", kitRoute("consent.tsx")),
23
- layout("_authenticated", kitRoute("_authenticated/route.tsx"), []),
24
- ]),
25
- ]);
18
+ export const createRoutes = (enabled: boolean) =>
19
+ rootRoute("__root.tsx", [
20
+ layout("_providers", kitRoute("route.tsx"), [
21
+ physical("."),
22
+ ...(enabled
23
+ ? [
24
+ route("/login", kitRoute("_auth-pages/login.tsx")),
25
+ route("/signup", kitRoute("_auth-pages/signUp.tsx")),
26
+ route("/consent", kitRoute("consent.tsx")),
27
+ ]
28
+ : []),
29
+ layout("_authenticated", kitRoute("_authenticated/route.tsx"), []),
30
+ ]),
31
+ ]);
32
+
33
+ const config = JSON.parse(
34
+ readFileSync(new URL("../../../disposabl.json", import.meta.url), "utf8"),
35
+ ) as { features: string[] };
36
+ export const routes = createRoutes(config.features.includes("authentication"));
26
37
 
27
38
  export default {
28
39
  routesDirectory: "router",
@@ -16,6 +16,6 @@ export default [
16
16
  },
17
17
  },
18
18
  {
19
- ignores: ["eslint.config.js", ".prettierrc"],
19
+ ignores: ["eslint.config.js", ".prettierrc", "mobile/**"],
20
20
  },
21
21
  ];
@@ -0,0 +1,4 @@
1
+ import config from "../../disposabl.json";
2
+
3
+ const features: readonly string[] = config.features;
4
+ export const authenticationEnabled = features.includes("authentication");
@@ -0,0 +1,125 @@
1
+ import {
2
+ useSignInWithUsernamePassword,
3
+ useSignUpWithUsernamePassword,
4
+ } from "@convex-dev/auth/methods/username-password/react";
5
+ import { Link, router } from "expo-router";
6
+ import { useRef, useState } from "react";
7
+ import {
8
+ Keyboard,
9
+ Text,
10
+ TextInput,
11
+ View,
12
+ type TextInputInstance,
13
+ } from "react-native";
14
+ import { api } from "../lib/convex";
15
+ import { authErrorMessage } from "../lib/auth-errors";
16
+ import { AuthButton, AuthScreen, styles } from "./auth-ui";
17
+
18
+ export function AuthForm({ mode }: { mode: "login" | "signup" }) {
19
+ const { signIn, pending: signingIn } = useSignInWithUsernamePassword(
20
+ api.auth,
21
+ );
22
+ const { signUp, pending: signingUp } = useSignUpWithUsernamePassword(
23
+ api.auth,
24
+ );
25
+ const [username, setUsername] = useState("");
26
+ const [password, setPassword] = useState("");
27
+ const [error, setError] = useState<string | null>(null);
28
+ const passwordInput = useRef<TextInputInstance>(null);
29
+ const submitting = useRef(false);
30
+ const pending = signingIn || signingUp;
31
+ const isSignup = mode === "signup";
32
+
33
+ async function submit() {
34
+ if (submitting.current || !username || !password) return;
35
+ submitting.current = true;
36
+ setError(null);
37
+ Keyboard.dismiss();
38
+ try {
39
+ const result = await (isSignup ? signUp : signIn)({ username, password });
40
+ if (result.status === "error") {
41
+ setError(authErrorMessage(result.userError));
42
+ } else {
43
+ setPassword("");
44
+ router.replace("/(authenticated)/account");
45
+ }
46
+ } finally {
47
+ submitting.current = false;
48
+ }
49
+ }
50
+
51
+ return (
52
+ <AuthScreen>
53
+ <Text style={styles.title}>
54
+ {isSignup ? "Create your account" : "Welcome back"}
55
+ </Text>
56
+ <Text style={styles.body}>
57
+ {isSignup
58
+ ? "Choose a username and password."
59
+ : "Use the same account as the website."}
60
+ </Text>
61
+ <View style={styles.field}>
62
+ <Text style={styles.label}>Username</Text>
63
+ <TextInput
64
+ accessibilityLabel="Username"
65
+ style={styles.input}
66
+ value={username}
67
+ onChangeText={setUsername}
68
+ autoCapitalize="none"
69
+ autoCorrect={false}
70
+ autoComplete={isSignup ? "username-new" : "username"}
71
+ textContentType="username"
72
+ editable={!pending}
73
+ returnKeyType="next"
74
+ submitBehavior="submit"
75
+ onSubmitEditing={() => passwordInput.current?.focus()}
76
+ />
77
+ </View>
78
+ <View style={styles.field}>
79
+ <Text style={styles.label}>Password</Text>
80
+ <TextInput
81
+ ref={passwordInput}
82
+ accessibilityLabel="Password"
83
+ style={styles.input}
84
+ value={password}
85
+ onChangeText={setPassword}
86
+ secureTextEntry
87
+ autoCapitalize="none"
88
+ autoCorrect={false}
89
+ autoComplete={isSignup ? "new-password" : "current-password"}
90
+ textContentType={isSignup ? "newPassword" : "password"}
91
+ editable={!pending}
92
+ returnKeyType="go"
93
+ onSubmitEditing={() => void submit()}
94
+ />
95
+ </View>
96
+ {error && (
97
+ <Text accessibilityRole="alert" style={styles.error}>
98
+ {error}
99
+ </Text>
100
+ )}
101
+ <AuthButton
102
+ title={
103
+ pending ? "Please wait..." : isSignup ? "Create account" : "Log in"
104
+ }
105
+ pending={pending}
106
+ disabled={!username || !password}
107
+ onPress={() => void submit()}
108
+ />
109
+ {!pending && (
110
+ <Link
111
+ replace
112
+ href={isSignup ? "/(auth)/login" : "/(auth)/signup"}
113
+ style={styles.link}
114
+ >
115
+ {isSignup
116
+ ? "Already have an account? Log in"
117
+ : "New here? Create an account"}
118
+ </Link>
119
+ )}
120
+ <Link href="/" style={styles.link}>
121
+ Back to home
122
+ </Link>
123
+ </AuthScreen>
124
+ );
125
+ }
@@ -0,0 +1,107 @@
1
+ import type { PropsWithChildren } from "react";
2
+ import {
3
+ ActivityIndicator,
4
+ KeyboardAvoidingView,
5
+ Platform,
6
+ Pressable,
7
+ ScrollView,
8
+ StyleSheet,
9
+ Text,
10
+ } from "react-native";
11
+ import { useHeaderHeight } from "expo-router/react-navigation";
12
+
13
+ export function AuthScreen({ children }: PropsWithChildren) {
14
+ const headerHeight = useHeaderHeight();
15
+ return (
16
+ <KeyboardAvoidingView
17
+ style={styles.screen}
18
+ behavior={Platform.OS === "ios" ? "padding" : undefined}
19
+ keyboardVerticalOffset={headerHeight}
20
+ >
21
+ <ScrollView
22
+ contentContainerStyle={styles.content}
23
+ keyboardShouldPersistTaps="handled"
24
+ >
25
+ {children}
26
+ </ScrollView>
27
+ </KeyboardAvoidingView>
28
+ );
29
+ }
30
+
31
+ export function AuthButton({
32
+ title,
33
+ onPress,
34
+ disabled = false,
35
+ pending = false,
36
+ }: {
37
+ title: string;
38
+ onPress: () => void;
39
+ disabled?: boolean;
40
+ pending?: boolean;
41
+ }) {
42
+ return (
43
+ <Pressable
44
+ accessibilityRole="button"
45
+ accessibilityState={{ disabled: disabled || pending, busy: pending }}
46
+ disabled={disabled || pending}
47
+ onPress={onPress}
48
+ style={({ pressed }) => [
49
+ styles.button,
50
+ (disabled || pending || pressed) && styles.dimmed,
51
+ ]}
52
+ >
53
+ {pending && <ActivityIndicator color="#fff" />}
54
+ <Text style={styles.buttonText}>{title}</Text>
55
+ </Pressable>
56
+ );
57
+ }
58
+
59
+ export const styles = StyleSheet.create({
60
+ screen: { flex: 1, backgroundColor: "#f5f6fa" },
61
+ content: {
62
+ flexGrow: 1,
63
+ justifyContent: "center",
64
+ padding: 24,
65
+ paddingBottom: 48,
66
+ gap: 20,
67
+ width: "100%",
68
+ maxWidth: 480,
69
+ alignSelf: "center",
70
+ },
71
+ title: { color: "#161b2e", fontSize: 32, fontWeight: "700" },
72
+ body: { color: "#495269", fontSize: 17, lineHeight: 25 },
73
+ label: { color: "#161b2e", fontSize: 16, fontWeight: "600" },
74
+ field: { gap: 8 },
75
+ input: {
76
+ minHeight: 52,
77
+ borderWidth: 1,
78
+ borderColor: "#bec5d4",
79
+ borderRadius: 12,
80
+ backgroundColor: "#fff",
81
+ padding: 14,
82
+ color: "#161b2e",
83
+ fontSize: 17,
84
+ },
85
+ button: {
86
+ minHeight: 52,
87
+ borderRadius: 12,
88
+ backgroundColor: "#2855c5",
89
+ flexDirection: "row",
90
+ alignItems: "center",
91
+ justifyContent: "center",
92
+ gap: 10,
93
+ padding: 14,
94
+ },
95
+ buttonText: { color: "#fff", fontSize: 17, fontWeight: "600" },
96
+ dimmed: { opacity: 0.6 },
97
+ link: { color: "#2855c5", fontSize: 17, paddingVertical: 12 },
98
+ error: { color: "#a31928", fontSize: 16, lineHeight: 23 },
99
+ card: {
100
+ backgroundColor: "#fff",
101
+ borderRadius: 16,
102
+ borderWidth: 1,
103
+ borderColor: "#e0e4ed",
104
+ padding: 20,
105
+ gap: 12,
106
+ },
107
+ });
@@ -0,0 +1,26 @@
1
+ const { withAppBuildGradle } = require("expo/config-plugins");
2
+
3
+ // RN's default bundle inputs cover the app directory, not workspace packages.
4
+ module.exports = (config) =>
5
+ withAppBuildGradle(config, (mod) => {
6
+ if (mod.modResults.language !== "groovy")
7
+ throw new Error("Expected a Groovy Android build");
8
+ const marker = "// Disposabl workspace bundle inputs.";
9
+ if (mod.modResults.contents.includes(marker)) return mod;
10
+ mod.modResults.contents += `
11
+ ${marker}
12
+ tasks.withType(com.facebook.react.tasks.BundleHermesCTask).configureEach {
13
+ inputs.files(fileTree(rootProject.file("../../../packages/disposabl-kit")) {
14
+ include "**/*.ts", "**/*.tsx", "**/*.js", "**/*.cjs", "package.json"
15
+ exclude "**/node_modules/**", "**/dist/**"
16
+ })
17
+ inputs.files(rootProject.file("../../../disposabl.json"),
18
+ rootProject.file("../../../package.json"),
19
+ rootProject.file("../../../bun.lock"))
20
+ inputs.files(fileTree(rootProject.file("..")) { include ".env", ".env.*" })
21
+ inputs.property("convexUrl", System.getenv("EXPO_PUBLIC_CONVEX_URL") ?: "")
22
+ inputs.property("convexSiteUrl", System.getenv("EXPO_PUBLIC_CONVEX_SITE_URL") ?: "")
23
+ }
24
+ `;
25
+ return mod;
26
+ });
@@ -0,0 +1,10 @@
1
+ export {
2
+ MobileLayout,
3
+ AuthLayout,
4
+ AuthenticatedLayout,
5
+ PublicLayout,
6
+ } from "./layout";
7
+ export { HomeScreen, PublicHomeScreen } from "./screens/home";
8
+ export { AccountScreen } from "./screens/account";
9
+ export { LoginScreen } from "./screens/login";
10
+ export { SignupScreen } from "./screens/signup";
@@ -0,0 +1,101 @@
1
+ import { ConvexAuthProvider } from "@convex-dev/auth/react";
2
+ import { ConvexProvider, ConvexReactClient, useConvexAuth } from "convex/react";
3
+ import { Redirect, Stack } from "expo-router";
4
+ import { useState } from "react";
5
+ import { ActivityIndicator, Text, View } from "react-native";
6
+ import { authenticationEnabled } from "../features";
7
+ import { styles } from "./components/auth-ui";
8
+ import { authStorage } from "./lib/auth-storage";
9
+ import { api } from "./lib/convex";
10
+
11
+ export function MobileLayout() {
12
+ const [client] = useState(() => {
13
+ const url = process.env.EXPO_PUBLIC_CONVEX_URL;
14
+ return url ? new ConvexReactClient(url) : null;
15
+ });
16
+
17
+ if (!client) {
18
+ return (
19
+ <View style={[styles.screen, styles.content]}>
20
+ <Text style={styles.title}>Connect your backend</Text>
21
+ <Text style={styles.body}>
22
+ Set EXPO_PUBLIC_CONVEX_URL in apps/mobile/.env.local, then rebuild the
23
+ app.
24
+ </Text>
25
+ </View>
26
+ );
27
+ }
28
+
29
+ if (!authenticationEnabled) {
30
+ return (
31
+ <ConvexProvider client={client}>
32
+ <PublicLayout />
33
+ </ConvexProvider>
34
+ );
35
+ }
36
+
37
+ return (
38
+ <ConvexAuthProvider
39
+ client={client}
40
+ api={api.auth}
41
+ storage={authStorage}
42
+ ambientSignIns={[]}
43
+ >
44
+ <SessionRoutes />
45
+ </ConvexAuthProvider>
46
+ );
47
+ }
48
+
49
+ function SessionRoutes() {
50
+ const { isAuthenticated } = useConvexAuth();
51
+ return <Routes isAuthenticated={isAuthenticated} />;
52
+ }
53
+
54
+ function Routes({ isAuthenticated = false }: { isAuthenticated?: boolean }) {
55
+ return (
56
+ <Stack screenOptions={{ headerTintColor: "#161b2e" }}>
57
+ <Stack.Screen name="index" options={{ title: "Disposabl" }} />
58
+ <Stack.Protected guard={!isAuthenticated}>
59
+ <Stack.Screen name="(auth)" options={{ headerShown: false }} />
60
+ </Stack.Protected>
61
+ <Stack.Screen name="(authenticated)" options={{ headerShown: false }} />
62
+ </Stack>
63
+ );
64
+ }
65
+
66
+ export function AuthLayout() {
67
+ return (
68
+ <Stack screenOptions={{ headerTintColor: "#161b2e" }}>
69
+ <Stack.Screen name="login" options={{ title: "Log in" }} />
70
+ <Stack.Screen name="signup" options={{ title: "Create account" }} />
71
+ </Stack>
72
+ );
73
+ }
74
+
75
+ // The route-group layout is the boundary: every descendant inherits this check.
76
+ // Public sibling routes need no guard and no separate route registry.
77
+ export function AuthenticatedLayout() {
78
+ const { isLoading, isAuthenticated } = useConvexAuth();
79
+ if (isLoading) {
80
+ return (
81
+ <View style={[styles.screen, styles.content]}>
82
+ <ActivityIndicator accessibilityLabel="Loading session" />
83
+ </View>
84
+ );
85
+ }
86
+ if (!isAuthenticated) return <Redirect href="/(auth)/login" />;
87
+ return <AccountRoutes />;
88
+ }
89
+
90
+ function AccountRoutes() {
91
+ return (
92
+ <Stack screenOptions={{ headerTintColor: "#161b2e" }}>
93
+ <Stack.Screen name="account" options={{ title: "Account" }} />
94
+ </Stack>
95
+ );
96
+ }
97
+
98
+ /** A route group without a session requirement. */
99
+ export function PublicLayout() {
100
+ return <Stack screenOptions={{ headerTintColor: "#161b2e" }} />;
101
+ }