create-bcp-app 0.1.15 → 0.1.16
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/package.json +1 -1
- package/src/index.mjs +37 -0
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -133,6 +133,10 @@ export async function createBcpApp(
|
|
|
133
133
|
targetDirectory,
|
|
134
134
|
selectedOptions.database
|
|
135
135
|
);
|
|
136
|
+
configureFrameworkAuthEntry(
|
|
137
|
+
targetDirectory,
|
|
138
|
+
selectedOptions.auth
|
|
139
|
+
);
|
|
136
140
|
|
|
137
141
|
fs.writeFileSync(
|
|
138
142
|
path.join(
|
|
@@ -374,6 +378,39 @@ function configureFrameworkDatabaseEntry(
|
|
|
374
378
|
);
|
|
375
379
|
}
|
|
376
380
|
|
|
381
|
+
function configureFrameworkAuthEntry(
|
|
382
|
+
targetDirectory,
|
|
383
|
+
auth
|
|
384
|
+
) {
|
|
385
|
+
if (
|
|
386
|
+
auth !== "jwt-cookie"
|
|
387
|
+
) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const authFile =
|
|
392
|
+
path.join(
|
|
393
|
+
targetDirectory,
|
|
394
|
+
"lib",
|
|
395
|
+
"auth.ts"
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
fs.mkdirSync(
|
|
399
|
+
path.dirname(
|
|
400
|
+
authFile
|
|
401
|
+
),
|
|
402
|
+
{
|
|
403
|
+
recursive: true,
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
fs.writeFileSync(
|
|
408
|
+
authFile,
|
|
409
|
+
`import {\n createAuth,\n type AuthUser,\n} from "bcp/auth";\n\nexport interface AuthenticatedUser extends AuthUser {\n id: string | number;\n email: string;\n role?: string;\n}\n\nexport interface UserSession {\n userId: string | number;\n email: string;\n role?: string;\n}\n\nconst frameworkAuth =\n createAuth<AuthenticatedUser>();\n\nexport const auth =\n frameworkAuth.auth;\nexport const getSession =\n frameworkAuth.getSession;\nexport const login =\n frameworkAuth.login;\nexport const logout =\n frameworkAuth.logout;\nexport const rotateSession =\n frameworkAuth.rotateSession;\n\nexport async function authenticateCredentials(\n email: string,\n password: string\n): Promise<AuthenticatedUser | null> {\n /*\n * Secure starter behavior: authentication is disabled until the\n * application verifies the supplied credentials against its own user\n * store and password-hash strategy.\n */\n void email;\n void password;\n\n return null;\n}\n\nexport async function createUserSession(\n user: AuthenticatedUser\n): Promise<void> {\n await login(\n user\n );\n}\n\nexport async function getCurrentUser(): Promise<UserSession | null> {\n const session =\n await auth();\n\n if (!session) {\n return null;\n }\n\n return {\n userId:\n session.user.id,\n email:\n session.user.email,\n ...(session.user.role === undefined\n ? {}\n : {\n role:\n session.user.role,\n }),\n };\n}\n\nexport async function clearUserSession(): Promise<void> {\n await logout();\n}\n`,
|
|
410
|
+
"utf8"
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
377
414
|
function readPackageMetadata() {
|
|
378
415
|
const packageJson =
|
|
379
416
|
JSON.parse(
|