@rapid-rn/plugin-auth 0.1.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.
- package/dist/index.cjs +188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
- package/templates/AuthGuard.tsx.hbs +110 -0
- package/templates/AuthHeader.tsx.hbs +91 -0
- package/templates/ForgotPasswordScreen.tsx.hbs +204 -0
- package/templates/LoginScreen.tsx.hbs +227 -0
- package/templates/OTPScreen.tsx.hbs +288 -0
- package/templates/SignupScreen.tsx.hbs +272 -0
- package/templates/auth.service.ts.hbs +158 -0
- package/templates/auth.store.ts.hbs +117 -0
- package/templates/index.ts.hbs +7 -0
- package/templates/useAuth.ts.hbs +137 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AuthPlugin: () => AuthPlugin,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// ../../../node_modules/.pnpm/tsup@8.5.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
39
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
40
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
41
|
+
|
|
42
|
+
// src/index.ts
|
|
43
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
44
|
+
var import_plugin_sdk = require("@rapid-rn/plugin-sdk");
|
|
45
|
+
var import_shared = require("@rapid-rn/shared");
|
|
46
|
+
var AuthPlugin = class extends import_plugin_sdk.BasePlugin {
|
|
47
|
+
manifest = {
|
|
48
|
+
id: "auth",
|
|
49
|
+
name: "Authentication",
|
|
50
|
+
version: "0.2.0",
|
|
51
|
+
description: "End-to-end auth module: Zustand store, Axios service with refresh token, AuthGuard, and all screens (Login, Signup, Forgot Password, OTP)",
|
|
52
|
+
supportedPlatforms: ["expo", "rncli"],
|
|
53
|
+
// All required plugins — the CLI injects these when the user selects "Auth"
|
|
54
|
+
requires: ["navigation", "zustand", "storage", "axios", "tanstack-query"],
|
|
55
|
+
optional: ["shared-components", "theme"],
|
|
56
|
+
npmPackages: [{ name: "@expo/vector-icons" }]
|
|
57
|
+
};
|
|
58
|
+
/** No sub-prompts — the CLI yes/no is the only decision point. */
|
|
59
|
+
prompts(_ctx) {
|
|
60
|
+
return Promise.resolve({});
|
|
61
|
+
}
|
|
62
|
+
validate(_ctx) {
|
|
63
|
+
return Promise.resolve({ valid: true, errors: [], warnings: [] });
|
|
64
|
+
}
|
|
65
|
+
async install(ctx, _answers) {
|
|
66
|
+
const templatesDir = (0, import_shared.resolveTemplatesDir)(importMetaUrl);
|
|
67
|
+
const engine = new import_shared.TemplateEngine();
|
|
68
|
+
const paths = ctx.platformAdapter.getProjectPaths(ctx.projectRoot, ctx.projectConfig);
|
|
69
|
+
const hasTheme = ctx.selectedPlugins.includes("theme");
|
|
70
|
+
const hasSharedComponents = ctx.selectedPlugins.includes("shared-components");
|
|
71
|
+
const hasOnboarding = ctx.selectedPlugins.includes("onboarding");
|
|
72
|
+
const data = {
|
|
73
|
+
hasTheme,
|
|
74
|
+
hasSharedComponents,
|
|
75
|
+
hasOnboarding
|
|
76
|
+
};
|
|
77
|
+
const files = [];
|
|
78
|
+
const authDir = import_node_path.default.join(paths.modules, "auth");
|
|
79
|
+
const authStore = await engine.renderFile(import_node_path.default.join(templatesDir, "auth.store.ts.hbs"), data);
|
|
80
|
+
files.push({
|
|
81
|
+
destinationPath: import_node_path.default.join(authDir, "store", "auth.store.ts"),
|
|
82
|
+
content: authStore,
|
|
83
|
+
overwrite: true
|
|
84
|
+
});
|
|
85
|
+
const authService = await engine.renderFile(
|
|
86
|
+
import_node_path.default.join(templatesDir, "auth.service.ts.hbs"),
|
|
87
|
+
data
|
|
88
|
+
);
|
|
89
|
+
files.push({
|
|
90
|
+
destinationPath: import_node_path.default.join(authDir, "services", "auth.service.ts"),
|
|
91
|
+
content: authService,
|
|
92
|
+
overwrite: true
|
|
93
|
+
});
|
|
94
|
+
const useAuth = await engine.renderFile(import_node_path.default.join(templatesDir, "useAuth.ts.hbs"), data);
|
|
95
|
+
files.push({
|
|
96
|
+
destinationPath: import_node_path.default.join(authDir, "hooks", "useAuth.ts"),
|
|
97
|
+
content: useAuth,
|
|
98
|
+
overwrite: true
|
|
99
|
+
});
|
|
100
|
+
const authGuard = await engine.renderFile(import_node_path.default.join(templatesDir, "AuthGuard.tsx.hbs"), data);
|
|
101
|
+
files.push({
|
|
102
|
+
destinationPath: import_node_path.default.join(authDir, "guards", "AuthGuard.tsx"),
|
|
103
|
+
content: authGuard,
|
|
104
|
+
overwrite: true
|
|
105
|
+
});
|
|
106
|
+
const authHeader = await engine.renderFile(import_node_path.default.join(templatesDir, "AuthHeader.tsx.hbs"), data);
|
|
107
|
+
files.push({
|
|
108
|
+
destinationPath: import_node_path.default.join(authDir, "components", "AuthHeader.tsx"),
|
|
109
|
+
content: authHeader,
|
|
110
|
+
overwrite: true
|
|
111
|
+
});
|
|
112
|
+
const screens = ["LoginScreen", "SignupScreen", "ForgotPasswordScreen", "OTPScreen"];
|
|
113
|
+
for (const screen of screens) {
|
|
114
|
+
const screenContent = await engine.renderFile(
|
|
115
|
+
import_node_path.default.join(templatesDir, `${screen}.tsx.hbs`),
|
|
116
|
+
data
|
|
117
|
+
);
|
|
118
|
+
files.push({
|
|
119
|
+
destinationPath: import_node_path.default.join(authDir, "screens", `${screen}.tsx`),
|
|
120
|
+
content: screenContent,
|
|
121
|
+
overwrite: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const navAnswers = ctx.projectConfig.pluginAnswers["navigation"];
|
|
125
|
+
const navLibrary = navAnswers?.["navLibrary"] || "expo-router";
|
|
126
|
+
if (navLibrary === "expo-router") {
|
|
127
|
+
files.push(
|
|
128
|
+
{
|
|
129
|
+
destinationPath: import_node_path.default.join(paths.app, "(auth)", "_layout.tsx"),
|
|
130
|
+
content: `import { Stack } from "expo-router";
|
|
131
|
+
|
|
132
|
+
export default function AuthLayout() {
|
|
133
|
+
return <Stack screenOptions={{ headerShown: false }} />;
|
|
134
|
+
}
|
|
135
|
+
`,
|
|
136
|
+
overwrite: true
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
destinationPath: import_node_path.default.join(paths.app, "(auth)", "login.tsx"),
|
|
140
|
+
content: `export { LoginScreen as default } from "../../src/modules/auth";
|
|
141
|
+
`,
|
|
142
|
+
overwrite: true
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
destinationPath: import_node_path.default.join(paths.app, "(auth)", "signup.tsx"),
|
|
146
|
+
content: `export { SignupScreen as default } from "../../src/modules/auth";
|
|
147
|
+
`,
|
|
148
|
+
overwrite: true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
destinationPath: import_node_path.default.join(paths.app, "(auth)", "forgot-password.tsx"),
|
|
152
|
+
content: `export { ForgotPasswordScreen as default } from "../../src/modules/auth";
|
|
153
|
+
`,
|
|
154
|
+
overwrite: true
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
destinationPath: import_node_path.default.join(paths.app, "(auth)", "otp.tsx"),
|
|
158
|
+
content: `export { OTPScreen as default } from "../../src/modules/auth";
|
|
159
|
+
`,
|
|
160
|
+
overwrite: true
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
const indexParts = [
|
|
165
|
+
'export * from "./screens/LoginScreen";',
|
|
166
|
+
'export * from "./screens/SignupScreen";',
|
|
167
|
+
'export * from "./screens/ForgotPasswordScreen";',
|
|
168
|
+
'export * from "./screens/OTPScreen";',
|
|
169
|
+
'export * from "./store/auth.store";',
|
|
170
|
+
'export * from "./services/auth.service";',
|
|
171
|
+
'export * from "./hooks/useAuth";',
|
|
172
|
+
'export * from "./guards/AuthGuard";',
|
|
173
|
+
'export * from "./components/AuthHeader";'
|
|
174
|
+
];
|
|
175
|
+
files.push({
|
|
176
|
+
destinationPath: import_node_path.default.join(authDir, "index.ts"),
|
|
177
|
+
content: indexParts.join("\n") + "\n",
|
|
178
|
+
overwrite: true
|
|
179
|
+
});
|
|
180
|
+
return { files };
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var index_default = AuthPlugin;
|
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
185
|
+
0 && (module.exports = {
|
|
186
|
+
AuthPlugin
|
|
187
|
+
});
|
|
188
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../../../node_modules/.pnpm/tsup@8.5.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["import path from \"node:path\";\nimport { BasePlugin } from \"@rapid-rn/plugin-sdk\";\nimport type {\n PluginContext,\n PluginInstallResult,\n PluginManifest,\n ValidationResult,\n PluginFile,\n} from \"@rapid-rn/plugin-sdk\";\nimport { resolveTemplatesDir, TemplateEngine } from \"@rapid-rn/shared\";\n\nexport class AuthPlugin extends BasePlugin {\n readonly manifest: PluginManifest = {\n id: \"auth\",\n name: \"Authentication\",\n version: \"0.2.0\",\n description:\n \"End-to-end auth module: Zustand store, Axios service with refresh token, \" +\n \"AuthGuard, and all screens (Login, Signup, Forgot Password, OTP)\",\n supportedPlatforms: [\"expo\", \"rncli\"],\n // All required plugins — the CLI injects these when the user selects \"Auth\"\n requires: [\"navigation\", \"zustand\", \"storage\", \"axios\", \"tanstack-query\"],\n optional: [\"shared-components\", \"theme\"],\n npmPackages: [{ name: \"@expo/vector-icons\" }],\n };\n\n /** No sub-prompts — the CLI yes/no is the only decision point. */\n prompts(_ctx: PluginContext): Promise<Record<string, unknown>> {\n return Promise.resolve({});\n }\n\n validate(_ctx: PluginContext): Promise<ValidationResult> {\n return Promise.resolve({ valid: true, errors: [], warnings: [] });\n }\n\n async install(\n ctx: PluginContext,\n _answers: Record<string, unknown>,\n ): Promise<PluginInstallResult> {\n const templatesDir = resolveTemplatesDir(import.meta.url);\n const engine = new TemplateEngine();\n const paths = ctx.platformAdapter.getProjectPaths(ctx.projectRoot, ctx.projectConfig);\n\n const hasTheme = ctx.selectedPlugins.includes(\"theme\");\n const hasSharedComponents = ctx.selectedPlugins.includes(\"shared-components\");\n const hasOnboarding = ctx.selectedPlugins.includes(\"onboarding\");\n\n const data = {\n hasTheme,\n hasSharedComponents,\n hasOnboarding,\n };\n\n const files: PluginFile[] = [];\n\n // All auth files live in src/modules/auth/\n const authDir = path.join(paths.modules, \"auth\");\n\n // 1. Zustand store\n const authStore = await engine.renderFile(path.join(templatesDir, \"auth.store.ts.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"store\", \"auth.store.ts\"),\n content: authStore,\n overwrite: true,\n });\n\n // 2. Auth service (API calls — dummy-ready)\n const authService = await engine.renderFile(\n path.join(templatesDir, \"auth.service.ts.hbs\"),\n data,\n );\n files.push({\n destinationPath: path.join(authDir, \"services\", \"auth.service.ts\"),\n content: authService,\n overwrite: true,\n });\n\n // 3. useAuth hook\n const useAuth = await engine.renderFile(path.join(templatesDir, \"useAuth.ts.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"hooks\", \"useAuth.ts\"),\n content: useAuth,\n overwrite: true,\n });\n\n // 4. AuthGuard component\n const authGuard = await engine.renderFile(path.join(templatesDir, \"AuthGuard.tsx.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"guards\", \"AuthGuard.tsx\"),\n content: authGuard,\n overwrite: true,\n });\n\n // 4b. AuthHeader component\n const authHeader = await engine.renderFile(path.join(templatesDir, \"AuthHeader.tsx.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"components\", \"AuthHeader.tsx\"),\n content: authHeader,\n overwrite: true,\n });\n\n // 5. Auth screens\n const screens = [\"LoginScreen\", \"SignupScreen\", \"ForgotPasswordScreen\", \"OTPScreen\"];\n for (const screen of screens) {\n const screenContent = await engine.renderFile(\n path.join(templatesDir, `${screen}.tsx.hbs`),\n data,\n );\n files.push({\n destinationPath: path.join(authDir, \"screens\", `${screen}.tsx`),\n content: screenContent,\n overwrite: true,\n });\n }\n\n // 6. Expo Router route re-exports in app/(auth)/\n const navAnswers = ctx.projectConfig.pluginAnswers[\"navigation\"];\n const navLibrary = (navAnswers?.[\"navLibrary\"] as string) || \"expo-router\";\n\n if (navLibrary === \"expo-router\") {\n files.push(\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"_layout.tsx\"),\n content: `import { Stack } from \"expo-router\";\\n\\nexport default function AuthLayout() {\\n return <Stack screenOptions=\\{{ headerShown: false }} />;\\n}\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"login.tsx\"),\n content: `export { LoginScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"signup.tsx\"),\n content: `export { SignupScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"forgot-password.tsx\"),\n content: `export { ForgotPasswordScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"otp.tsx\"),\n content: `export { OTPScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n );\n }\n\n // 7. Module barrel export\n const indexParts = [\n 'export * from \"./screens/LoginScreen\";',\n 'export * from \"./screens/SignupScreen\";',\n 'export * from \"./screens/ForgotPasswordScreen\";',\n 'export * from \"./screens/OTPScreen\";',\n 'export * from \"./store/auth.store\";',\n 'export * from \"./services/auth.service\";',\n 'export * from \"./hooks/useAuth\";',\n 'export * from \"./guards/AuthGuard\";',\n 'export * from \"./components/AuthHeader\";',\n ];\n\n files.push({\n destinationPath: path.join(authDir, \"index.ts\"),\n content: indexParts.join(\"\\n\") + \"\\n\",\n overwrite: true,\n });\n\n return { files };\n }\n}\n\nexport default AuthPlugin;\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ADZ9D,uBAAiB;AACjB,wBAA2B;AAQ3B,oBAAoD;AAE7C,IAAM,aAAN,cAAyB,6BAAW;AAAA,EAChC,WAA2B;AAAA,IAClC,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aACE;AAAA,IAEF,oBAAoB,CAAC,QAAQ,OAAO;AAAA;AAAA,IAEpC,UAAU,CAAC,cAAc,WAAW,WAAW,SAAS,gBAAgB;AAAA,IACxE,UAAU,CAAC,qBAAqB,OAAO;AAAA,IACvC,aAAa,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAAA,EAC9C;AAAA;AAAA,EAGA,QAAQ,MAAuD;AAC7D,WAAO,QAAQ,QAAQ,CAAC,CAAC;AAAA,EAC3B;AAAA,EAEA,SAAS,MAAgD;AACvD,WAAO,QAAQ,QAAQ,EAAE,OAAO,MAAM,QAAQ,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC;AAAA,EAClE;AAAA,EAEA,MA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AAqB;AAAA,UACrE,SAAS;AAAA;AAAA,UACT,WAAW;AAAA,QACb;AAAA,QACA;AAAA,UACE,iBAAiB,iBAAAA,QAAK,KAAK,MAAM,KAAK,UAAU,SAAS;AAAA,UACzD,SAAS;AAAA;AAAA,UACT,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IACF;AAGA,UAAM,aAAa;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,UAAM,KAAK;AAAA,MACT,iBAAiB,iBAAAA,QAAK,KAAK,SAAS,UAAU;AAAA,MAC9C,SAAS,WAAW,KAAK,IAAI,IAAI;AAAA,MACjC,WAAW;AAAA,IACb,CAAC;AAED,WAAO,EAAE,MAAM;AAAA,EACjB;AACF;AAEA,IAAO,gBAAQ;","names":["path"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BasePlugin, PluginManifest, PluginContext, ValidationResult, PluginInstallResult } from '@rapid-rn/plugin-sdk';
|
|
2
|
+
|
|
3
|
+
declare class AuthPlugin extends BasePlugin {
|
|
4
|
+
readonly manifest: PluginManifest;
|
|
5
|
+
/** No sub-prompts — the CLI yes/no is the only decision point. */
|
|
6
|
+
prompts(_ctx: PluginContext): Promise<Record<string, unknown>>;
|
|
7
|
+
validate(_ctx: PluginContext): Promise<ValidationResult>;
|
|
8
|
+
install(ctx: PluginContext, _answers: Record<string, unknown>): Promise<PluginInstallResult>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { AuthPlugin, AuthPlugin as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BasePlugin, PluginManifest, PluginContext, ValidationResult, PluginInstallResult } from '@rapid-rn/plugin-sdk';
|
|
2
|
+
|
|
3
|
+
declare class AuthPlugin extends BasePlugin {
|
|
4
|
+
readonly manifest: PluginManifest;
|
|
5
|
+
/** No sub-prompts — the CLI yes/no is the only decision point. */
|
|
6
|
+
prompts(_ctx: PluginContext): Promise<Record<string, unknown>>;
|
|
7
|
+
validate(_ctx: PluginContext): Promise<ValidationResult>;
|
|
8
|
+
install(ctx: PluginContext, _answers: Record<string, unknown>): Promise<PluginInstallResult>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { AuthPlugin, AuthPlugin as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { BasePlugin } from "@rapid-rn/plugin-sdk";
|
|
4
|
+
import { resolveTemplatesDir, TemplateEngine } from "@rapid-rn/shared";
|
|
5
|
+
var AuthPlugin = class extends BasePlugin {
|
|
6
|
+
manifest = {
|
|
7
|
+
id: "auth",
|
|
8
|
+
name: "Authentication",
|
|
9
|
+
version: "0.2.0",
|
|
10
|
+
description: "End-to-end auth module: Zustand store, Axios service with refresh token, AuthGuard, and all screens (Login, Signup, Forgot Password, OTP)",
|
|
11
|
+
supportedPlatforms: ["expo", "rncli"],
|
|
12
|
+
// All required plugins — the CLI injects these when the user selects "Auth"
|
|
13
|
+
requires: ["navigation", "zustand", "storage", "axios", "tanstack-query"],
|
|
14
|
+
optional: ["shared-components", "theme"],
|
|
15
|
+
npmPackages: [{ name: "@expo/vector-icons" }]
|
|
16
|
+
};
|
|
17
|
+
/** No sub-prompts — the CLI yes/no is the only decision point. */
|
|
18
|
+
prompts(_ctx) {
|
|
19
|
+
return Promise.resolve({});
|
|
20
|
+
}
|
|
21
|
+
validate(_ctx) {
|
|
22
|
+
return Promise.resolve({ valid: true, errors: [], warnings: [] });
|
|
23
|
+
}
|
|
24
|
+
async install(ctx, _answers) {
|
|
25
|
+
const templatesDir = resolveTemplatesDir(import.meta.url);
|
|
26
|
+
const engine = new TemplateEngine();
|
|
27
|
+
const paths = ctx.platformAdapter.getProjectPaths(ctx.projectRoot, ctx.projectConfig);
|
|
28
|
+
const hasTheme = ctx.selectedPlugins.includes("theme");
|
|
29
|
+
const hasSharedComponents = ctx.selectedPlugins.includes("shared-components");
|
|
30
|
+
const hasOnboarding = ctx.selectedPlugins.includes("onboarding");
|
|
31
|
+
const data = {
|
|
32
|
+
hasTheme,
|
|
33
|
+
hasSharedComponents,
|
|
34
|
+
hasOnboarding
|
|
35
|
+
};
|
|
36
|
+
const files = [];
|
|
37
|
+
const authDir = path.join(paths.modules, "auth");
|
|
38
|
+
const authStore = await engine.renderFile(path.join(templatesDir, "auth.store.ts.hbs"), data);
|
|
39
|
+
files.push({
|
|
40
|
+
destinationPath: path.join(authDir, "store", "auth.store.ts"),
|
|
41
|
+
content: authStore,
|
|
42
|
+
overwrite: true
|
|
43
|
+
});
|
|
44
|
+
const authService = await engine.renderFile(
|
|
45
|
+
path.join(templatesDir, "auth.service.ts.hbs"),
|
|
46
|
+
data
|
|
47
|
+
);
|
|
48
|
+
files.push({
|
|
49
|
+
destinationPath: path.join(authDir, "services", "auth.service.ts"),
|
|
50
|
+
content: authService,
|
|
51
|
+
overwrite: true
|
|
52
|
+
});
|
|
53
|
+
const useAuth = await engine.renderFile(path.join(templatesDir, "useAuth.ts.hbs"), data);
|
|
54
|
+
files.push({
|
|
55
|
+
destinationPath: path.join(authDir, "hooks", "useAuth.ts"),
|
|
56
|
+
content: useAuth,
|
|
57
|
+
overwrite: true
|
|
58
|
+
});
|
|
59
|
+
const authGuard = await engine.renderFile(path.join(templatesDir, "AuthGuard.tsx.hbs"), data);
|
|
60
|
+
files.push({
|
|
61
|
+
destinationPath: path.join(authDir, "guards", "AuthGuard.tsx"),
|
|
62
|
+
content: authGuard,
|
|
63
|
+
overwrite: true
|
|
64
|
+
});
|
|
65
|
+
const authHeader = await engine.renderFile(path.join(templatesDir, "AuthHeader.tsx.hbs"), data);
|
|
66
|
+
files.push({
|
|
67
|
+
destinationPath: path.join(authDir, "components", "AuthHeader.tsx"),
|
|
68
|
+
content: authHeader,
|
|
69
|
+
overwrite: true
|
|
70
|
+
});
|
|
71
|
+
const screens = ["LoginScreen", "SignupScreen", "ForgotPasswordScreen", "OTPScreen"];
|
|
72
|
+
for (const screen of screens) {
|
|
73
|
+
const screenContent = await engine.renderFile(
|
|
74
|
+
path.join(templatesDir, `${screen}.tsx.hbs`),
|
|
75
|
+
data
|
|
76
|
+
);
|
|
77
|
+
files.push({
|
|
78
|
+
destinationPath: path.join(authDir, "screens", `${screen}.tsx`),
|
|
79
|
+
content: screenContent,
|
|
80
|
+
overwrite: true
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const navAnswers = ctx.projectConfig.pluginAnswers["navigation"];
|
|
84
|
+
const navLibrary = navAnswers?.["navLibrary"] || "expo-router";
|
|
85
|
+
if (navLibrary === "expo-router") {
|
|
86
|
+
files.push(
|
|
87
|
+
{
|
|
88
|
+
destinationPath: path.join(paths.app, "(auth)", "_layout.tsx"),
|
|
89
|
+
content: `import { Stack } from "expo-router";
|
|
90
|
+
|
|
91
|
+
export default function AuthLayout() {
|
|
92
|
+
return <Stack screenOptions={{ headerShown: false }} />;
|
|
93
|
+
}
|
|
94
|
+
`,
|
|
95
|
+
overwrite: true
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
destinationPath: path.join(paths.app, "(auth)", "login.tsx"),
|
|
99
|
+
content: `export { LoginScreen as default } from "../../src/modules/auth";
|
|
100
|
+
`,
|
|
101
|
+
overwrite: true
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
destinationPath: path.join(paths.app, "(auth)", "signup.tsx"),
|
|
105
|
+
content: `export { SignupScreen as default } from "../../src/modules/auth";
|
|
106
|
+
`,
|
|
107
|
+
overwrite: true
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
destinationPath: path.join(paths.app, "(auth)", "forgot-password.tsx"),
|
|
111
|
+
content: `export { ForgotPasswordScreen as default } from "../../src/modules/auth";
|
|
112
|
+
`,
|
|
113
|
+
overwrite: true
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
destinationPath: path.join(paths.app, "(auth)", "otp.tsx"),
|
|
117
|
+
content: `export { OTPScreen as default } from "../../src/modules/auth";
|
|
118
|
+
`,
|
|
119
|
+
overwrite: true
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const indexParts = [
|
|
124
|
+
'export * from "./screens/LoginScreen";',
|
|
125
|
+
'export * from "./screens/SignupScreen";',
|
|
126
|
+
'export * from "./screens/ForgotPasswordScreen";',
|
|
127
|
+
'export * from "./screens/OTPScreen";',
|
|
128
|
+
'export * from "./store/auth.store";',
|
|
129
|
+
'export * from "./services/auth.service";',
|
|
130
|
+
'export * from "./hooks/useAuth";',
|
|
131
|
+
'export * from "./guards/AuthGuard";',
|
|
132
|
+
'export * from "./components/AuthHeader";'
|
|
133
|
+
];
|
|
134
|
+
files.push({
|
|
135
|
+
destinationPath: path.join(authDir, "index.ts"),
|
|
136
|
+
content: indexParts.join("\n") + "\n",
|
|
137
|
+
overwrite: true
|
|
138
|
+
});
|
|
139
|
+
return { files };
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var index_default = AuthPlugin;
|
|
143
|
+
export {
|
|
144
|
+
AuthPlugin,
|
|
145
|
+
index_default as default
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport { BasePlugin } from \"@rapid-rn/plugin-sdk\";\nimport type {\n PluginContext,\n PluginInstallResult,\n PluginManifest,\n ValidationResult,\n PluginFile,\n} from \"@rapid-rn/plugin-sdk\";\nimport { resolveTemplatesDir, TemplateEngine } from \"@rapid-rn/shared\";\n\nexport class AuthPlugin extends BasePlugin {\n readonly manifest: PluginManifest = {\n id: \"auth\",\n name: \"Authentication\",\n version: \"0.2.0\",\n description:\n \"End-to-end auth module: Zustand store, Axios service with refresh token, \" +\n \"AuthGuard, and all screens (Login, Signup, Forgot Password, OTP)\",\n supportedPlatforms: [\"expo\", \"rncli\"],\n // All required plugins — the CLI injects these when the user selects \"Auth\"\n requires: [\"navigation\", \"zustand\", \"storage\", \"axios\", \"tanstack-query\"],\n optional: [\"shared-components\", \"theme\"],\n npmPackages: [{ name: \"@expo/vector-icons\" }],\n };\n\n /** No sub-prompts — the CLI yes/no is the only decision point. */\n prompts(_ctx: PluginContext): Promise<Record<string, unknown>> {\n return Promise.resolve({});\n }\n\n validate(_ctx: PluginContext): Promise<ValidationResult> {\n return Promise.resolve({ valid: true, errors: [], warnings: [] });\n }\n\n async install(\n ctx: PluginContext,\n _answers: Record<string, unknown>,\n ): Promise<PluginInstallResult> {\n const templatesDir = resolveTemplatesDir(import.meta.url);\n const engine = new TemplateEngine();\n const paths = ctx.platformAdapter.getProjectPaths(ctx.projectRoot, ctx.projectConfig);\n\n const hasTheme = ctx.selectedPlugins.includes(\"theme\");\n const hasSharedComponents = ctx.selectedPlugins.includes(\"shared-components\");\n const hasOnboarding = ctx.selectedPlugins.includes(\"onboarding\");\n\n const data = {\n hasTheme,\n hasSharedComponents,\n hasOnboarding,\n };\n\n const files: PluginFile[] = [];\n\n // All auth files live in src/modules/auth/\n const authDir = path.join(paths.modules, \"auth\");\n\n // 1. Zustand store\n const authStore = await engine.renderFile(path.join(templatesDir, \"auth.store.ts.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"store\", \"auth.store.ts\"),\n content: authStore,\n overwrite: true,\n });\n\n // 2. Auth service (API calls — dummy-ready)\n const authService = await engine.renderFile(\n path.join(templatesDir, \"auth.service.ts.hbs\"),\n data,\n );\n files.push({\n destinationPath: path.join(authDir, \"services\", \"auth.service.ts\"),\n content: authService,\n overwrite: true,\n });\n\n // 3. useAuth hook\n const useAuth = await engine.renderFile(path.join(templatesDir, \"useAuth.ts.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"hooks\", \"useAuth.ts\"),\n content: useAuth,\n overwrite: true,\n });\n\n // 4. AuthGuard component\n const authGuard = await engine.renderFile(path.join(templatesDir, \"AuthGuard.tsx.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"guards\", \"AuthGuard.tsx\"),\n content: authGuard,\n overwrite: true,\n });\n\n // 4b. AuthHeader component\n const authHeader = await engine.renderFile(path.join(templatesDir, \"AuthHeader.tsx.hbs\"), data);\n files.push({\n destinationPath: path.join(authDir, \"components\", \"AuthHeader.tsx\"),\n content: authHeader,\n overwrite: true,\n });\n\n // 5. Auth screens\n const screens = [\"LoginScreen\", \"SignupScreen\", \"ForgotPasswordScreen\", \"OTPScreen\"];\n for (const screen of screens) {\n const screenContent = await engine.renderFile(\n path.join(templatesDir, `${screen}.tsx.hbs`),\n data,\n );\n files.push({\n destinationPath: path.join(authDir, \"screens\", `${screen}.tsx`),\n content: screenContent,\n overwrite: true,\n });\n }\n\n // 6. Expo Router route re-exports in app/(auth)/\n const navAnswers = ctx.projectConfig.pluginAnswers[\"navigation\"];\n const navLibrary = (navAnswers?.[\"navLibrary\"] as string) || \"expo-router\";\n\n if (navLibrary === \"expo-router\") {\n files.push(\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"_layout.tsx\"),\n content: `import { Stack } from \"expo-router\";\\n\\nexport default function AuthLayout() {\\n return <Stack screenOptions=\\{{ headerShown: false }} />;\\n}\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"login.tsx\"),\n content: `export { LoginScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"signup.tsx\"),\n content: `export { SignupScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"forgot-password.tsx\"),\n content: `export { ForgotPasswordScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n {\n destinationPath: path.join(paths.app, \"(auth)\", \"otp.tsx\"),\n content: `export { OTPScreen as default } from \"../../src/modules/auth\";\\n`,\n overwrite: true,\n },\n );\n }\n\n // 7. Module barrel export\n const indexParts = [\n 'export * from \"./screens/LoginScreen\";',\n 'export * from \"./screens/SignupScreen\";',\n 'export * from \"./screens/ForgotPasswordScreen\";',\n 'export * from \"./screens/OTPScreen\";',\n 'export * from \"./store/auth.store\";',\n 'export * from \"./services/auth.service\";',\n 'export * from \"./hooks/useAuth\";',\n 'export * from \"./guards/AuthGuard\";',\n 'export * from \"./components/AuthHeader\";',\n ];\n\n files.push({\n destinationPath: path.join(authDir, \"index.ts\"),\n content: indexParts.join(\"\\n\") + \"\\n\",\n overwrite: true,\n });\n\n return { files };\n }\n}\n\nexport default AuthPlugin;\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,SAAS,kBAAkB;AAQ3B,SAAS,qBAAqB,sBAAsB;AAE7C,IAAM,aAAN,cAAyB,WAAW;AAAA,EAChC,WAA2B;AAAA,IAClC,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aACE;AAAA,IAEF,oBAAoB,CAAC,QAAQ,OAAO;AAAA;AAAA,IAEpC,UAAU,CAAC,cAAc,WAAW,WAAW,SAAS,gBAAgB;AAAA,IACxE,UAAU,CAAC,qBAAqB,OAAO;AAAA,IACvC,aAAa,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAAA,EAC9C;AAAA;AAAA,EAGA,QAAQ,MAAuD;AAC7D,WAAO,QAAQ,QAAQ,CAAC,CAAC;AAAA,EAC3B;AAAA,EAEA,SAAS,MAAgD;AACvD,WAAO,QAAQ,QAAQ,EAAE,OAAO,MAAM,QAAQ,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,QACJ,KACA,UAC8B;AAC9B,UAAM,eAAe,oBAAoB,YAAY,GAAG;AACxD,UAAM,SAAS,IAAI,eAAe;AAClC,UAAM,QAAQ,IAAI,gBAAgB,gBAAgB,IAAI,aAAa,IAAI,aAAa;AAEpF,UAAM,WAAW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AAA,IACF;AAEA,UAAM,KAAK;AAAA,MACT,iBAAiB,KAAK,KAAK,SAAS,UAAU;AAAA,MAC9C,SAAS,WAAW,KAAK,IAAI,IAAI;AAAA,MACjC,WAAW;AAAA,IACb,CAAC;AAED,WAAO,EAAE,MAAM;AAAA,EACjB;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rapid-rn/plugin-auth",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Full auth flow: screens, guards, hook, and store integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"templates"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@clack/prompts": "^0.7.0",
|
|
22
|
+
"@rapid-rn/plugin-sdk": "0.1.0",
|
|
23
|
+
"@rapid-rn/shared": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"rimraf": "^5.0.5",
|
|
27
|
+
"tsup": "^8.0.2",
|
|
28
|
+
"typescript": "^5.4.2"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"dev": "tsup --watch",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"clean": "rimraf dist *.tsbuildinfo"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { ActivityIndicator, View, StyleSheet } from "react-native";
|
|
3
|
+
import { useSegments, useRouter } from "expo-router";
|
|
4
|
+
import { useAuthStore } from "../store/auth.store";
|
|
5
|
+
{{#if hasOnboarding}}
|
|
6
|
+
import { useOnboarding } from "../../onboarding/hooks/useOnboarding";
|
|
7
|
+
{{/if}}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* AuthGuard — Protects routes based on authentication state.
|
|
11
|
+
*
|
|
12
|
+
* Behaviour:
|
|
13
|
+
* • Calls initializeAuth() on mount to restore tokens from storage.
|
|
14
|
+
* • Shows a loading spinner while the auth state is being initialised.
|
|
15
|
+
* • Redirects to /(auth)/login when the user is not authenticated.
|
|
16
|
+
* • Redirects to /(tabs) when the user is authenticated but on an auth screen.
|
|
17
|
+
*
|
|
18
|
+
* Note: when hasSplash is true, initializeAuth() is already called in _layout.tsx
|
|
19
|
+
* in parallel with the splash timer, so by the time this component mounts the
|
|
20
|
+
* auth state is ready and the spinner is shown for < 1 frame.
|
|
21
|
+
*
|
|
22
|
+
* Usage (in app/_layout.tsx — already wired by the generator):
|
|
23
|
+
* <AuthGuard>
|
|
24
|
+
* <Stack>...</Stack>
|
|
25
|
+
* </AuthGuard>
|
|
26
|
+
*/
|
|
27
|
+
export const AuthGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
28
|
+
const { isAuthenticated, isInitializing, initializeAuth } = useAuthStore();
|
|
29
|
+
{{#if hasOnboarding}}
|
|
30
|
+
const { completed: onboardingComplete, loading: onboardingLoading } = useOnboarding();
|
|
31
|
+
{{/if}}
|
|
32
|
+
const segments = useSegments();
|
|
33
|
+
const router = useRouter();
|
|
34
|
+
|
|
35
|
+
// Restore auth state from storage on mount.
|
|
36
|
+
// This is a no-op if _layout.tsx already called initializeAuth().
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
initializeAuth();
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
// Route guard — runs whenever auth state, onboarding state, or current route changes.
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (isInitializing) return; // Wait until auth state is loaded
|
|
44
|
+
|
|
45
|
+
{{#if hasOnboarding}}
|
|
46
|
+
if (onboardingLoading) return; // Wait until onboarding state is loaded
|
|
47
|
+
{{/if}}
|
|
48
|
+
|
|
49
|
+
const segList = segments as string[];
|
|
50
|
+
const inAuthGroup = segList[0] === "(auth)";
|
|
51
|
+
const atRoot = segList.length === 0 || segList[0] === "" || segList[0] === "index";
|
|
52
|
+
|
|
53
|
+
{{#if hasOnboarding}}
|
|
54
|
+
// If onboarding is not completed, let index.tsx render OnboardingScreen.
|
|
55
|
+
// Force them back to root if they try to access other protected/auth routes.
|
|
56
|
+
if (!onboardingComplete) {
|
|
57
|
+
if (!atRoot) {
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
router.replace("/");
|
|
60
|
+
}, 0);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
{{/if}}
|
|
65
|
+
|
|
66
|
+
if (!isAuthenticated) {
|
|
67
|
+
// Not logged in: must be in auth group
|
|
68
|
+
if (!inAuthGroup) {
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
router.replace("/(auth)/login");
|
|
71
|
+
}, 0);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
// Logged in: must NOT be in auth group and shouldn't linger on root index
|
|
75
|
+
if (inAuthGroup || atRoot) {
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
router.replace("/(tabs)");
|
|
78
|
+
}, 0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, [
|
|
82
|
+
isAuthenticated,
|
|
83
|
+
segments,
|
|
84
|
+
isInitializing,
|
|
85
|
+
{{#if hasOnboarding}}
|
|
86
|
+
onboardingComplete,
|
|
87
|
+
onboardingLoading,
|
|
88
|
+
{{/if}}
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
// Show a loading indicator while auth state (and onboarding state) is being restored.
|
|
92
|
+
if (isInitializing{{#if hasOnboarding}} || onboardingLoading{{/if}}) {
|
|
93
|
+
return (
|
|
94
|
+
<View style={styles.loader}>
|
|
95
|
+
<ActivityIndicator size="large" color="#6C63FF" />
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return <>{children}</>;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const styles = StyleSheet.create({
|
|
104
|
+
loader: {
|
|
105
|
+
flex: 1,
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
justifyContent: "center",
|
|
108
|
+
backgroundColor: "#fff",
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet, Text, View, TouchableOpacity, StyleProp, ViewStyle, TextStyle } from "react-native";
|
|
3
|
+
import { useRouter } from "expo-router";
|
|
4
|
+
import { Ionicons } from "@expo/vector-icons";
|
|
5
|
+
{{#if hasTheme}}
|
|
6
|
+
import { useTheme } from "@theme";
|
|
7
|
+
{{/if}}
|
|
8
|
+
|
|
9
|
+
interface AuthHeaderProps {
|
|
10
|
+
title?: string;
|
|
11
|
+
showBackButton?: boolean;
|
|
12
|
+
onBackPress?: () => void;
|
|
13
|
+
style?: StyleProp<ViewStyle>;
|
|
14
|
+
titleStyle?: StyleProp<TextStyle>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const AuthHeader: React.FC<AuthHeaderProps> = ({
|
|
18
|
+
title,
|
|
19
|
+
showBackButton = true,
|
|
20
|
+
onBackPress,
|
|
21
|
+
style,
|
|
22
|
+
titleStyle,
|
|
23
|
+
}) => {
|
|
24
|
+
const router = useRouter();
|
|
25
|
+
{{#if hasTheme}}
|
|
26
|
+
const { colors, typography } = useTheme();
|
|
27
|
+
{{/if}}
|
|
28
|
+
|
|
29
|
+
const handleBack = () => {
|
|
30
|
+
if (onBackPress) {
|
|
31
|
+
onBackPress();
|
|
32
|
+
} else {
|
|
33
|
+
router.back();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const bgColor = {{#if hasTheme}}colors.background{{else}}"#fff"{{/if}};
|
|
38
|
+
const textColor = {{#if hasTheme}}colors.text{{else}}"#111"{{/if}};
|
|
39
|
+
const primaryColor = {{#if hasTheme}}colors.primary{{else}}"#6C63FF"{{/if}};
|
|
40
|
+
const boldFont = {{#if hasTheme}}typography.fonts.bold{{else}}undefined{{/if}};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View style={[styles.container, { backgroundColor: bgColor }, style]}>
|
|
44
|
+
<View style={styles.leftContainer}>
|
|
45
|
+
{showBackButton && (
|
|
46
|
+
<TouchableOpacity onPress={handleBack} style={styles.backButton}>
|
|
47
|
+
<Ionicons name="arrow-back" size={24} color={primaryColor} />
|
|
48
|
+
</TouchableOpacity>
|
|
49
|
+
)}
|
|
50
|
+
</View>
|
|
51
|
+
<View style={styles.titleContainer}>
|
|
52
|
+
{title && (
|
|
53
|
+
<Text style={[styles.title, { color: textColor, fontFamily: boldFont }, titleStyle]}>
|
|
54
|
+
{title}
|
|
55
|
+
</Text>
|
|
56
|
+
)}
|
|
57
|
+
</View>
|
|
58
|
+
<View style={styles.rightContainer} />
|
|
59
|
+
</View>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const styles = StyleSheet.create({
|
|
64
|
+
container: {
|
|
65
|
+
flexDirection: "row",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
justifyContent: "space-between",
|
|
68
|
+
height: 56,
|
|
69
|
+
paddingHorizontal: 16,
|
|
70
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
71
|
+
borderBottomColor: "#e0e0e0",
|
|
72
|
+
},
|
|
73
|
+
leftContainer: {
|
|
74
|
+
width: 40,
|
|
75
|
+
alignItems: "flex-start",
|
|
76
|
+
},
|
|
77
|
+
titleContainer: {
|
|
78
|
+
flex: 1,
|
|
79
|
+
alignItems: "center",
|
|
80
|
+
},
|
|
81
|
+
rightContainer: {
|
|
82
|
+
width: 40,
|
|
83
|
+
},
|
|
84
|
+
backButton: {
|
|
85
|
+
padding: 4,
|
|
86
|
+
},
|
|
87
|
+
title: {
|
|
88
|
+
fontSize: 18,
|
|
89
|
+
fontWeight: "600",
|
|
90
|
+
},
|
|
91
|
+
});
|