@cedarjs/auth-dbauth-setup 2.8.1-next.0 → 2.8.1-next.109
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.js +20 -18
- package/dist/setup.js +69 -32
- package/dist/setupData.js +148 -23
- package/dist/setupHandler.js +110 -81
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +84 -58
- package/dist/webAuthn.setupData.d.ts.map +1 -1
- package/dist/webAuthn.setupData.js +133 -33
- package/package.json +9 -13
package/dist/index.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./setup"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./setup")
|
|
9
22
|
});
|
|
10
|
-
var _setup = require("./setup");
|
|
11
|
-
_forEachInstanceProperty(_context = _Object$keys(_setup)).call(_context, function (key) {
|
|
12
|
-
if (key === "default" || key === "__esModule") return;
|
|
13
|
-
if (key in exports && exports[key] === _setup[key]) return;
|
|
14
|
-
_Object$defineProperty(exports, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return _setup[key];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
});
|
package/dist/setup.js
CHANGED
|
@@ -1,41 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
var setup_exports = {};
|
|
30
|
+
__export(setup_exports, {
|
|
31
|
+
builder: () => builder,
|
|
32
|
+
command: () => command,
|
|
33
|
+
description: () => description,
|
|
34
|
+
handler: () => handler
|
|
6
35
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const description = exports.description = 'Set up auth for for dbAuth';
|
|
36
|
+
module.exports = __toCommonJS(setup_exports);
|
|
37
|
+
var import_termi_link = require("termi-link");
|
|
38
|
+
const command = "dbAuth";
|
|
39
|
+
const description = "Set up auth for for dbAuth";
|
|
12
40
|
function builder(yargs) {
|
|
13
|
-
yargs.option(
|
|
14
|
-
alias:
|
|
41
|
+
yargs.option("force", {
|
|
42
|
+
alias: "f",
|
|
15
43
|
default: false,
|
|
16
|
-
description:
|
|
17
|
-
type:
|
|
18
|
-
}).option(
|
|
19
|
-
alias:
|
|
44
|
+
description: "Overwrite existing configuration",
|
|
45
|
+
type: "boolean"
|
|
46
|
+
}).option("webauthn", {
|
|
47
|
+
alias: "w",
|
|
20
48
|
default: null,
|
|
21
|
-
description:
|
|
22
|
-
type:
|
|
23
|
-
}).option(
|
|
24
|
-
alias:
|
|
49
|
+
description: "Include WebAuthn support (TouchID/FaceID)",
|
|
50
|
+
type: "boolean"
|
|
51
|
+
}).option("createUserModel", {
|
|
52
|
+
alias: "u",
|
|
25
53
|
default: null,
|
|
26
|
-
description:
|
|
27
|
-
type:
|
|
28
|
-
}).option(
|
|
29
|
-
alias:
|
|
54
|
+
description: "Create a User database model",
|
|
55
|
+
type: "boolean"
|
|
56
|
+
}).option("generateAuthPages", {
|
|
57
|
+
alias: "g",
|
|
30
58
|
default: null,
|
|
31
|
-
description:
|
|
32
|
-
type:
|
|
33
|
-
}).epilogue(
|
|
59
|
+
description: "Generate auth pages (login, signup, etc.)",
|
|
60
|
+
type: "boolean"
|
|
61
|
+
}).epilogue(
|
|
62
|
+
`Also see the ${(0, import_termi_link.terminalLink)(
|
|
63
|
+
"CedarJS CLI Reference",
|
|
64
|
+
"https://cedarjs.com/docs/cli-commands#setup-auth"
|
|
65
|
+
)}`
|
|
66
|
+
);
|
|
34
67
|
}
|
|
35
|
-
const handler = async options => {
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
} = await import('./setupHandler.js');
|
|
39
|
-
return handler(options);
|
|
68
|
+
const handler = async (options) => {
|
|
69
|
+
const { handler: handler2 } = await import("./setupHandler.js");
|
|
70
|
+
return handler2(options);
|
|
40
71
|
};
|
|
41
|
-
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
builder,
|
|
75
|
+
command,
|
|
76
|
+
description,
|
|
77
|
+
handler
|
|
78
|
+
});
|
package/dist/setupData.js
CHANGED
|
@@ -1,25 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
var setupData_exports = {};
|
|
30
|
+
__export(setupData_exports, {
|
|
31
|
+
createUserModelTask: () => createUserModelTask,
|
|
32
|
+
extraTask: () => extraTask,
|
|
33
|
+
noteGenerate: () => noteGenerate,
|
|
34
|
+
notes: () => notes,
|
|
35
|
+
notesCreatedUserModel: () => notesCreatedUserModel
|
|
7
36
|
});
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
const secret =
|
|
14
|
-
const extraTask =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
37
|
+
module.exports = __toCommonJS(setupData_exports);
|
|
38
|
+
var import_node_crypto = __toESM(require("node:crypto"));
|
|
39
|
+
var import_node_path = __toESM(require("node:path"));
|
|
40
|
+
var import_cli_helpers = require("@cedarjs/cli-helpers");
|
|
41
|
+
var import_shared = require("./shared");
|
|
42
|
+
const secret = import_node_crypto.default.randomBytes(32).toString("base64");
|
|
43
|
+
const extraTask = (0, import_cli_helpers.addEnvVarTask)(
|
|
44
|
+
"SESSION_SECRET",
|
|
45
|
+
secret,
|
|
46
|
+
"Used to encrypt/decrypt session cookies. Change this value and re-deploy to log out all users of your app at once."
|
|
47
|
+
);
|
|
48
|
+
const createUserModelTask = {
|
|
49
|
+
title: "Creating model `User`...",
|
|
50
|
+
task: async (ctx) => {
|
|
51
|
+
const hasUserModel = await (0, import_shared.hasModel)("User");
|
|
19
52
|
if (hasUserModel && !ctx.force) {
|
|
20
|
-
throw new Error(
|
|
53
|
+
throw new Error("User model already exists");
|
|
21
54
|
}
|
|
22
|
-
(0,
|
|
55
|
+
(0, import_shared.addModels)(`
|
|
23
56
|
model User {
|
|
24
57
|
id String @id @default(uuid())
|
|
25
58
|
email String @unique
|
|
@@ -33,8 +66,100 @@ model User {
|
|
|
33
66
|
`);
|
|
34
67
|
}
|
|
35
68
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
69
|
+
const notes = [
|
|
70
|
+
`${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
|
|
71
|
+
`,
|
|
72
|
+
"You will need to add a couple of fields to your User table in order",
|
|
73
|
+
"to store a hashed password and salt:",
|
|
74
|
+
"",
|
|
75
|
+
" model User {",
|
|
76
|
+
" id String @id @default(uuid())",
|
|
77
|
+
" email String @unique",
|
|
78
|
+
" hashedPassword String // <\u2500\u2510",
|
|
79
|
+
" salt String // <\u2500\u253C\u2500 add these lines",
|
|
80
|
+
" resetToken String? // <\u2500\u2524",
|
|
81
|
+
" resetTokenExpiresAt DateTime? // <\u2500\u2518",
|
|
82
|
+
" }",
|
|
83
|
+
"",
|
|
84
|
+
"If you already have existing user records you will need to provide",
|
|
85
|
+
"a default value for `hashedPassword` and `salt` or Prisma complains, so",
|
|
86
|
+
"change those to: ",
|
|
87
|
+
"",
|
|
88
|
+
' hashedPassword String @default("")',
|
|
89
|
+
' salt String @default("")',
|
|
90
|
+
"",
|
|
91
|
+
"If you expose any of your user data via GraphQL be sure to exclude",
|
|
92
|
+
"`hashedPassword` and `salt` (or whatever you named them) from the",
|
|
93
|
+
"SDL file that defines the fields for your user.",
|
|
94
|
+
"",
|
|
95
|
+
"You'll need to let Cedar know what fields you're using for your users'",
|
|
96
|
+
"`id` and `username` fields. In this case we're using `id` and `email`,",
|
|
97
|
+
"so update those in the `authFields` config in",
|
|
98
|
+
`\`${import_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
|
|
99
|
+
"you used a different name for the `hashedPassword`, `salt`,",
|
|
100
|
+
"`resetToken` or `resetTokenExpiresAt`, fields:`",
|
|
101
|
+
"",
|
|
102
|
+
" authFields: {",
|
|
103
|
+
" id: 'id',",
|
|
104
|
+
" username: 'email',",
|
|
105
|
+
" hashedPassword: 'hashedPassword',",
|
|
106
|
+
" salt: 'salt',",
|
|
107
|
+
" resetToken: 'resetToken',",
|
|
108
|
+
" resetTokenExpiresAt: 'resetTokenExpiresAt',",
|
|
109
|
+
" },",
|
|
110
|
+
"",
|
|
111
|
+
"To get the actual user that's logged in, take a look at `getCurrentUser()`",
|
|
112
|
+
`in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
113
|
+
"use different names for your model or unique ID fields, in which case you",
|
|
114
|
+
"need to update those calls (instructions are in the comment above the code).",
|
|
115
|
+
"",
|
|
116
|
+
"Finally, we created a SESSION_SECRET environment variable for you in",
|
|
117
|
+
`${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
|
|
118
|
+
"into version control and should be unique for each environment you",
|
|
119
|
+
"deploy to. If you ever need to log everyone out of your app at once",
|
|
120
|
+
"change this secret to a new value and deploy. To create a new secret, run:",
|
|
121
|
+
"",
|
|
122
|
+
" yarn cedar generate secret",
|
|
123
|
+
""
|
|
124
|
+
];
|
|
125
|
+
const notesCreatedUserModel = [
|
|
126
|
+
`${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
|
|
127
|
+
`,
|
|
128
|
+
"If you expose any of your user data via GraphQL be sure to exclude",
|
|
129
|
+
"`hashedPassword` and `salt` (or whatever you named them) from the",
|
|
130
|
+
"SDL file that defines the fields for your user.",
|
|
131
|
+
"",
|
|
132
|
+
"To get the actual user that's logged in, take a look at `getCurrentUser()`",
|
|
133
|
+
`in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
134
|
+
"use different names for your model or unique ID fields, in which case you",
|
|
135
|
+
"need to update those calls (instructions are in the comment above the code).",
|
|
136
|
+
"",
|
|
137
|
+
"Finally, we created a SESSION_SECRET environment variable for you in",
|
|
138
|
+
`${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
|
|
139
|
+
"into version control and should be unique for each environment you",
|
|
140
|
+
"deploy to. If you ever need to log everyone out of your app at once",
|
|
141
|
+
"change this secret to a new value and deploy. To create a new secret, run:",
|
|
142
|
+
"",
|
|
143
|
+
" yarn cedar generate secret",
|
|
144
|
+
"",
|
|
145
|
+
"A new User model was added to your schema. Don't forget to migrate your db",
|
|
146
|
+
"before you try using dbAuth:",
|
|
147
|
+
"",
|
|
148
|
+
" yarn cedar prisma migrate dev",
|
|
149
|
+
""
|
|
150
|
+
];
|
|
151
|
+
const noteGenerate = [
|
|
152
|
+
"",
|
|
153
|
+
"Need simple Login, Signup and Forgot Password pages? We've got a generator",
|
|
154
|
+
"for those as well:",
|
|
155
|
+
"",
|
|
156
|
+
" yarn cedar generate dbAuth"
|
|
157
|
+
];
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {
|
|
160
|
+
createUserModelTask,
|
|
161
|
+
extraTask,
|
|
162
|
+
noteGenerate,
|
|
163
|
+
notes,
|
|
164
|
+
notesCreatedUserModel
|
|
165
|
+
});
|
package/dist/setupHandler.js
CHANGED
|
@@ -1,84 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
var setupHandler_exports = {};
|
|
30
|
+
__export(setupHandler_exports, {
|
|
31
|
+
createAuthDecoderFunction: () => createAuthDecoderFunction,
|
|
32
|
+
handler: () => handler
|
|
7
33
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
require("
|
|
12
|
-
require("
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var _cliHelpers = require("@cedarjs/cli-helpers");
|
|
17
|
-
var _setupData = require("./setupData");
|
|
18
|
-
var _shared = require("./shared");
|
|
19
|
-
var _webAuthn = require("./webAuthn.setupData");
|
|
34
|
+
module.exports = __toCommonJS(setupHandler_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
|
+
var import_prompts = __toESM(require("prompts"));
|
|
38
|
+
var import_cli_helpers = require("@cedarjs/cli-helpers");
|
|
39
|
+
var import_setupData = require("./setupData");
|
|
40
|
+
var import_shared = require("./shared");
|
|
41
|
+
var import_webAuthn = require("./webAuthn.setupData");
|
|
20
42
|
async function handler({
|
|
21
43
|
webauthn,
|
|
22
44
|
createUserModel,
|
|
23
45
|
generateAuthPages,
|
|
24
46
|
force: forceArg
|
|
25
47
|
}) {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
48
|
+
const { version } = JSON.parse(
|
|
49
|
+
import_node_fs.default.readFileSync(import_node_path.default.resolve(__dirname, "../package.json"), "utf-8")
|
|
50
|
+
);
|
|
29
51
|
const webAuthn = await shouldIncludeWebAuthn(webauthn);
|
|
30
52
|
const createDbUserModel = await shouldCreateUserModel(createUserModel);
|
|
31
53
|
const generateDbAuthPages = await shouldGenerateDbAuthPages(generateAuthPages);
|
|
32
54
|
const oneMoreThing = [];
|
|
33
55
|
if (webAuthn) {
|
|
34
56
|
if (createDbUserModel) {
|
|
35
|
-
oneMoreThing.push(...
|
|
57
|
+
oneMoreThing.push(...import_setupData.notesCreatedUserModel);
|
|
36
58
|
} else {
|
|
37
|
-
oneMoreThing.push(...
|
|
59
|
+
oneMoreThing.push(...import_webAuthn.notes);
|
|
38
60
|
}
|
|
39
61
|
if (!generateDbAuthPages) {
|
|
40
|
-
oneMoreThing.push(...
|
|
62
|
+
oneMoreThing.push(...import_webAuthn.noteGenerate);
|
|
41
63
|
}
|
|
42
64
|
} else {
|
|
43
65
|
if (createDbUserModel) {
|
|
44
|
-
oneMoreThing.push(...
|
|
66
|
+
oneMoreThing.push(...import_setupData.notesCreatedUserModel);
|
|
45
67
|
} else {
|
|
46
|
-
oneMoreThing.push(...
|
|
68
|
+
oneMoreThing.push(...import_setupData.notes);
|
|
47
69
|
}
|
|
48
70
|
if (!generateDbAuthPages) {
|
|
49
|
-
oneMoreThing.push(...
|
|
71
|
+
oneMoreThing.push(...import_setupData.noteGenerate);
|
|
50
72
|
}
|
|
51
73
|
}
|
|
52
|
-
let createDbUserModelTask =
|
|
74
|
+
let createDbUserModelTask = void 0;
|
|
53
75
|
if (createDbUserModel) {
|
|
54
76
|
if (webAuthn) {
|
|
55
|
-
createDbUserModelTask =
|
|
77
|
+
createDbUserModelTask = import_webAuthn.createUserModelTask;
|
|
56
78
|
} else {
|
|
57
|
-
createDbUserModelTask =
|
|
79
|
+
createDbUserModelTask = import_setupData.createUserModelTask;
|
|
58
80
|
}
|
|
59
81
|
}
|
|
60
|
-
await (0,
|
|
82
|
+
await (0, import_cli_helpers.standardAuthHandler)({
|
|
61
83
|
basedir: __dirname,
|
|
62
84
|
forceArg,
|
|
63
|
-
provider:
|
|
85
|
+
provider: "dbAuth",
|
|
64
86
|
authDecoderImport: "import { createAuthDecoder } from '@cedarjs/auth-dbauth-api'",
|
|
65
87
|
webAuthn,
|
|
66
|
-
webPackages: [
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
webPackages: [
|
|
89
|
+
`@cedarjs/auth-dbauth-web@${version}`,
|
|
90
|
+
...webAuthn ? import_webAuthn.webPackages : []
|
|
91
|
+
],
|
|
92
|
+
apiPackages: [
|
|
93
|
+
`@cedarjs/auth-dbauth-api@${version}`,
|
|
94
|
+
...webAuthn ? import_webAuthn.apiPackages : []
|
|
95
|
+
],
|
|
96
|
+
extraTasks: [
|
|
97
|
+
webAuthn ? import_webAuthn.extraTask : import_setupData.extraTask,
|
|
98
|
+
createDbUserModelTask,
|
|
99
|
+
createAuthDecoderFunction,
|
|
100
|
+
generateDbAuthPages ? (0, import_shared.generateAuthPagesTask)(createDbUserModel) : void 0
|
|
101
|
+
],
|
|
69
102
|
notes: oneMoreThing
|
|
70
103
|
});
|
|
71
104
|
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Prompt the user (unless already specified on the command line) if they want
|
|
75
|
-
* to enable WebAuthn support
|
|
76
|
-
*/
|
|
77
105
|
async function shouldIncludeWebAuthn(webauthn) {
|
|
78
106
|
if (webauthn === null) {
|
|
79
|
-
const webAuthnResponse = await (0,
|
|
80
|
-
type:
|
|
81
|
-
name:
|
|
107
|
+
const webAuthnResponse = await (0, import_prompts.default)({
|
|
108
|
+
type: "confirm",
|
|
109
|
+
name: "answer",
|
|
82
110
|
message: `Enable WebAuthn support (TouchID/FaceID)? See https://cedarjs.com/docs/auth/dbAuth#webAuthn`,
|
|
83
111
|
initial: false
|
|
84
112
|
});
|
|
@@ -86,69 +114,70 @@ async function shouldIncludeWebAuthn(webauthn) {
|
|
|
86
114
|
}
|
|
87
115
|
return webauthn;
|
|
88
116
|
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Prompt the user (unless already specified on the command line) if they want
|
|
92
|
-
* to create a User model in their Prisma schema
|
|
93
|
-
*/
|
|
94
117
|
async function shouldCreateUserModel(createUserModel) {
|
|
95
|
-
const hasUserModel = await (0,
|
|
96
|
-
const modelNames = await (0,
|
|
97
|
-
const isNewProject = modelNames.length === 1 && modelNames[0] ===
|
|
118
|
+
const hasUserModel = await (0, import_shared.hasModel)("User");
|
|
119
|
+
const modelNames = await (0, import_shared.getModelNames)();
|
|
120
|
+
const isNewProject = modelNames.length === 1 && modelNames[0] === "UserExample";
|
|
98
121
|
if (isNewProject) {
|
|
99
122
|
return true;
|
|
100
123
|
}
|
|
101
124
|
if (createUserModel === null && !hasUserModel) {
|
|
102
|
-
const createModelResponse = await (0,
|
|
103
|
-
type:
|
|
104
|
-
name:
|
|
105
|
-
message:
|
|
125
|
+
const createModelResponse = await (0, import_prompts.default)({
|
|
126
|
+
type: "confirm",
|
|
127
|
+
name: "answer",
|
|
128
|
+
message: "Create User model?",
|
|
106
129
|
initial: false
|
|
107
130
|
});
|
|
108
131
|
return createModelResponse.answer;
|
|
109
132
|
}
|
|
110
133
|
return createUserModel;
|
|
111
134
|
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Prompt the user (unless already specified on the command line) if they want
|
|
115
|
-
* to generate auth pages. Also checks to make sure auth pages don't already
|
|
116
|
-
* exist before prompting.
|
|
117
|
-
*/
|
|
118
135
|
async function shouldGenerateDbAuthPages(generateAuthPages) {
|
|
119
|
-
if (generateAuthPages === null && !(0,
|
|
120
|
-
const generateAuthPagesResponse = await (0,
|
|
121
|
-
type:
|
|
122
|
-
name:
|
|
123
|
-
message:
|
|
136
|
+
if (generateAuthPages === null && !(0, import_shared.hasAuthPages)()) {
|
|
137
|
+
const generateAuthPagesResponse = await (0, import_prompts.default)({
|
|
138
|
+
type: "confirm",
|
|
139
|
+
name: "answer",
|
|
140
|
+
message: "Generate auth pages (login, signup, forgotten password, etc)?",
|
|
124
141
|
initial: false
|
|
125
142
|
});
|
|
126
143
|
return generateAuthPagesResponse.answer;
|
|
127
144
|
}
|
|
128
145
|
return generateAuthPages;
|
|
129
146
|
}
|
|
130
|
-
const createAuthDecoderFunction =
|
|
131
|
-
title:
|
|
147
|
+
const createAuthDecoderFunction = {
|
|
148
|
+
title: "Create auth decoder function",
|
|
132
149
|
task: () => {
|
|
133
|
-
const graphqlPath = (0,
|
|
150
|
+
const graphqlPath = (0, import_cli_helpers.getGraphqlPath)();
|
|
134
151
|
if (!graphqlPath) {
|
|
135
|
-
throw new Error(
|
|
152
|
+
throw new Error("Could not find your graphql file path");
|
|
136
153
|
}
|
|
137
|
-
const authDecoderCreation =
|
|
138
|
-
const content =
|
|
139
|
-
let newContent = content.replace(
|
|
140
|
-
|
|
154
|
+
const authDecoderCreation = "const authDecoder = createAuthDecoder(cookieName)";
|
|
155
|
+
const content = import_node_fs.default.readFileSync(graphqlPath, "utf-8");
|
|
156
|
+
let newContent = content.replace(
|
|
157
|
+
"import { getCurrentUser } from",
|
|
158
|
+
"import { cookieName, getCurrentUser } from"
|
|
159
|
+
);
|
|
160
|
+
const authDecoderCreationRegexp = new RegExp(
|
|
161
|
+
"^" + escapeRegExp(authDecoderCreation),
|
|
162
|
+
"m"
|
|
163
|
+
);
|
|
141
164
|
if (!authDecoderCreationRegexp.test(newContent)) {
|
|
142
|
-
newContent = newContent.replace(
|
|
165
|
+
newContent = newContent.replace(
|
|
166
|
+
"export const handler = createGraphQLHandler({",
|
|
167
|
+
authDecoderCreation + "\n\nexport const handler = createGraphQLHandler({"
|
|
168
|
+
);
|
|
143
169
|
}
|
|
144
|
-
if (!
|
|
145
|
-
throw new Error(
|
|
170
|
+
if (!newContent.includes("import { cookieName")) {
|
|
171
|
+
throw new Error("Failed to import cookieName");
|
|
146
172
|
}
|
|
147
|
-
|
|
173
|
+
import_node_fs.default.writeFileSync(graphqlPath, newContent);
|
|
148
174
|
}
|
|
149
175
|
};
|
|
150
|
-
|
|
151
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
152
176
|
function escapeRegExp(str) {
|
|
153
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g,
|
|
154
|
-
}
|
|
177
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
createAuthDecoderFunction,
|
|
182
|
+
handler
|
|
183
|
+
});
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,OAAO,QAAkD,CAAA;AACtE,eAAO,MAAM,aAAa,QAGzB,CAAA;AAED,eAAO,MAAM,aAAa,yBAMzB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,qBAe1C,CAAA;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,iBAS7C;AAED,wBAAgB,YAAY,YAuB3B;AAED,wBAAgB,qBAAqB,CAAC,mBAAmB,EAAE,OAAO;;;EAwBjE"}
|
package/dist/shared.js
CHANGED
|
@@ -1,75 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
var shared_exports = {};
|
|
30
|
+
__export(shared_exports, {
|
|
31
|
+
addModels: () => addModels,
|
|
32
|
+
functionsPath: () => functionsPath,
|
|
33
|
+
generateAuthPagesTask: () => generateAuthPagesTask,
|
|
34
|
+
getModelNames: () => getModelNames,
|
|
35
|
+
hasAuthPages: () => hasAuthPages,
|
|
36
|
+
hasModel: () => hasModel,
|
|
37
|
+
libPath: () => libPath
|
|
7
38
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
require("
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var _internals = require("@prisma/internals");
|
|
21
|
-
var _execa = _interopRequireDefault(require("execa"));
|
|
22
|
-
var _cliHelpers = require("@cedarjs/cli-helpers");
|
|
23
|
-
var _projectConfig = require("@cedarjs/project-config");
|
|
24
|
-
const libPath = exports.libPath = (0, _cliHelpers.getPaths)().api.lib.replace((0, _cliHelpers.getPaths)().base, '');
|
|
25
|
-
const functionsPath = exports.functionsPath = (0, _cliHelpers.getPaths)().api.functions.replace((0, _cliHelpers.getPaths)().base, '');
|
|
39
|
+
module.exports = __toCommonJS(shared_exports);
|
|
40
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
41
|
+
var import_node_path = __toESM(require("node:path"));
|
|
42
|
+
var import_internals = require("@prisma/internals");
|
|
43
|
+
var import_execa = __toESM(require("execa"));
|
|
44
|
+
var import_cli_helpers = require("@cedarjs/cli-helpers");
|
|
45
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
46
|
+
const libPath = (0, import_cli_helpers.getPaths)().api.lib.replace((0, import_cli_helpers.getPaths)().base, "");
|
|
47
|
+
const functionsPath = (0, import_cli_helpers.getPaths)().api.functions.replace(
|
|
48
|
+
(0, import_cli_helpers.getPaths)().base,
|
|
49
|
+
""
|
|
50
|
+
);
|
|
26
51
|
const getModelNames = async () => {
|
|
27
|
-
|
|
28
|
-
const schemaPath = await (0, _projectConfig.getSchemaPath)((0, _cliHelpers.getPaths)().api.prismaConfig);
|
|
29
|
-
const result = await (0, _internals.getSchemaWithPath)(schemaPath);
|
|
52
|
+
const result = await (0, import_project_config.getPrismaSchemas)();
|
|
30
53
|
const datamodel = result.schemas;
|
|
31
|
-
const schema = await (0,
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
return (0, _map.default)(_context = schema.datamodel.models).call(_context, model => model.name);
|
|
54
|
+
const schema = await (0, import_internals.getDMMF)({ datamodel });
|
|
55
|
+
return schema.datamodel.models.map((model) => model.name);
|
|
35
56
|
};
|
|
36
|
-
|
|
37
|
-
const hasModel = async name => {
|
|
38
|
-
var _context2;
|
|
57
|
+
const hasModel = async (name) => {
|
|
39
58
|
if (!name) {
|
|
40
59
|
return false;
|
|
41
60
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const modelName = name.replace(/[_-]/g, '').toLowerCase();
|
|
46
|
-
const modelNames = (0, _map.default)(_context2 = await getModelNames()).call(_context2, name => name.toLowerCase());
|
|
47
|
-
if ((0, _includes.default)(modelNames).call(modelNames, modelName)) {
|
|
61
|
+
const modelName = name.replace(/[_-]/g, "").toLowerCase();
|
|
62
|
+
const modelNames = (await getModelNames()).map((name2) => name2.toLowerCase());
|
|
63
|
+
if (modelNames.includes(modelName)) {
|
|
48
64
|
return true;
|
|
49
65
|
}
|
|
50
66
|
return false;
|
|
51
67
|
};
|
|
52
|
-
exports.hasModel = hasModel;
|
|
53
68
|
async function addModels(models) {
|
|
54
|
-
const schemaPath = await (0,
|
|
55
|
-
const isDirectory =
|
|
69
|
+
const schemaPath = await (0, import_project_config.getSchemaPath)((0, import_cli_helpers.getPaths)().api.prismaConfig);
|
|
70
|
+
const isDirectory = import_node_fs.default.statSync(schemaPath).isDirectory();
|
|
56
71
|
if (isDirectory) {
|
|
57
|
-
|
|
72
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(schemaPath, "user.prisma"), models);
|
|
58
73
|
} else {
|
|
59
|
-
|
|
74
|
+
import_node_fs.default.appendFileSync(schemaPath, models);
|
|
60
75
|
}
|
|
61
76
|
}
|
|
62
77
|
function hasAuthPages() {
|
|
63
|
-
|
|
64
|
-
const routes = _nodeFs.default.readFileSync((0, _cliHelpers.getPaths)().web.routes, 'utf-8');
|
|
65
|
-
|
|
66
|
-
// If the user already has a route for /login, /signin, or /signup, we
|
|
67
|
-
// assume auth pages are already set up
|
|
78
|
+
const routes = import_node_fs.default.readFileSync((0, import_cli_helpers.getPaths)().web.routes, "utf-8");
|
|
68
79
|
if (/path={?['"]\/(login|signin|signup)['"]}? /i.test(routes)) {
|
|
69
80
|
return true;
|
|
70
81
|
}
|
|
71
|
-
return (0,
|
|
72
|
-
if (page.importName ===
|
|
82
|
+
return (0, import_project_config.processPagesDir)().some((page) => {
|
|
83
|
+
if (page.importName === "LoginPage" || page.importName === "LogInPage" || page.importName === "SigninPage" || page.importName === "SignInPage" || page.importName === "SignupPage" || page.importName === "SignUpPage") {
|
|
73
84
|
return true;
|
|
74
85
|
}
|
|
75
86
|
return false;
|
|
@@ -77,18 +88,33 @@ function hasAuthPages() {
|
|
|
77
88
|
}
|
|
78
89
|
function generateAuthPagesTask(generatingUserModel) {
|
|
79
90
|
return {
|
|
80
|
-
title:
|
|
91
|
+
title: "Adding dbAuth pages...",
|
|
81
92
|
task: async () => {
|
|
82
|
-
const rwjsPaths = (0,
|
|
83
|
-
const args = [
|
|
93
|
+
const rwjsPaths = (0, import_cli_helpers.getPaths)();
|
|
94
|
+
const args = ["cedar", "g", "dbAuth"];
|
|
84
95
|
if (generatingUserModel) {
|
|
85
|
-
args.push(
|
|
96
|
+
args.push(
|
|
97
|
+
"--username-label",
|
|
98
|
+
"username",
|
|
99
|
+
"--password-label",
|
|
100
|
+
"password"
|
|
101
|
+
);
|
|
86
102
|
}
|
|
87
|
-
await (0,
|
|
88
|
-
stdio:
|
|
103
|
+
await (0, import_execa.default)("yarn", args, {
|
|
104
|
+
stdio: "inherit",
|
|
89
105
|
shell: true,
|
|
90
106
|
cwd: rwjsPaths.base
|
|
91
107
|
});
|
|
92
108
|
}
|
|
93
109
|
};
|
|
94
|
-
}
|
|
110
|
+
}
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
addModels,
|
|
114
|
+
functionsPath,
|
|
115
|
+
generateAuthPagesTask,
|
|
116
|
+
getModelNames,
|
|
117
|
+
hasAuthPages,
|
|
118
|
+
hasModel,
|
|
119
|
+
libPath
|
|
120
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webAuthn.setupData.d.ts","sourceRoot":"","sources":["../src/webAuthn.setupData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAA;AAKlF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"webAuthn.setupData.d.ts","sourceRoot":"","sources":["../src/webAuthn.setupData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAA;AAKlF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,eAAO,MAAM,WAAW,UAAkC,CAAA;AAG1D,eAAO,MAAM,WAAW,UAAiC,CAAA;AAEzD,eAAO,MAAM,mBAAmB;;gBAEZ,gBAAgB;CA+BnC,CAAA;AAGD,eAAO,MAAM,KAAK,UAoEjB,CAAA;AAED,eAAO,MAAM,YAAY,UAMxB,CAAA"}
|
|
@@ -1,37 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 });
|
|
13
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
|
+
var webAuthn_setupData_exports = {};
|
|
30
|
+
__export(webAuthn_setupData_exports, {
|
|
31
|
+
apiPackages: () => apiPackages,
|
|
32
|
+
createUserModelTask: () => createUserModelTask,
|
|
33
|
+
extraTask: () => import_setupData.extraTask,
|
|
34
|
+
noteGenerate: () => noteGenerate,
|
|
35
|
+
notes: () => notes,
|
|
36
|
+
webPackages: () => webPackages
|
|
14
37
|
});
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const apiPackages = exports.apiPackages = ['@simplewebauthn/server@^9'];
|
|
27
|
-
const createUserModelTask = exports.createUserModelTask = {
|
|
28
|
-
title: 'Creating model `User`...',
|
|
29
|
-
task: async ctx => {
|
|
30
|
-
const hasUserModel = await (0, _shared.hasModel)('User');
|
|
38
|
+
module.exports = __toCommonJS(webAuthn_setupData_exports);
|
|
39
|
+
var import_node_path = __toESM(require("node:path"));
|
|
40
|
+
var import_cli_helpers = require("@cedarjs/cli-helpers");
|
|
41
|
+
var import_shared = require("./shared");
|
|
42
|
+
var import_setupData = require("./setupData");
|
|
43
|
+
const webPackages = ["@simplewebauthn/browser@^10"];
|
|
44
|
+
const apiPackages = ["@simplewebauthn/server@^10"];
|
|
45
|
+
const createUserModelTask = {
|
|
46
|
+
title: "Creating model `User`...",
|
|
47
|
+
task: async (ctx) => {
|
|
48
|
+
const hasUserModel = await (0, import_shared.hasModel)("User");
|
|
31
49
|
if (hasUserModel && !ctx.force) {
|
|
32
|
-
throw new Error(
|
|
50
|
+
throw new Error("User model already exists");
|
|
33
51
|
}
|
|
34
|
-
(0,
|
|
52
|
+
(0, import_shared.addModels)(`
|
|
35
53
|
model User {
|
|
36
54
|
id String @id @default(uuid())
|
|
37
55
|
email String @unique
|
|
@@ -56,7 +74,89 @@ model UserCredential {
|
|
|
56
74
|
`);
|
|
57
75
|
}
|
|
58
76
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
const notes = [
|
|
78
|
+
`${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
|
|
79
|
+
`,
|
|
80
|
+
"You will need to add a couple of fields to your User table in order",
|
|
81
|
+
"to store a hashed password, salt, reset token, and to connect it to",
|
|
82
|
+
"a new UserCredential model to keep track of any devices used with",
|
|
83
|
+
"WebAuthn authentication:",
|
|
84
|
+
"",
|
|
85
|
+
" model User {",
|
|
86
|
+
" id String @id @default(uuid())",
|
|
87
|
+
" email String @unique",
|
|
88
|
+
" hashedPassword String",
|
|
89
|
+
" salt String",
|
|
90
|
+
" resetToken String?",
|
|
91
|
+
" resetTokenExpiresAt DateTime?",
|
|
92
|
+
" webAuthnChallenge String? @unique",
|
|
93
|
+
" credentials UserCredential[]",
|
|
94
|
+
" }",
|
|
95
|
+
"",
|
|
96
|
+
" model UserCredential {",
|
|
97
|
+
" id String @id",
|
|
98
|
+
" userId String",
|
|
99
|
+
" user User @relation(fields: [userId], references: [id])",
|
|
100
|
+
" publicKey Bytes",
|
|
101
|
+
" transports String?",
|
|
102
|
+
" counter BigInt",
|
|
103
|
+
" }",
|
|
104
|
+
"",
|
|
105
|
+
"If you already have existing user records you will need to provide",
|
|
106
|
+
"a default value for `hashedPassword` and `salt` or Prisma complains, so",
|
|
107
|
+
"change those to: ",
|
|
108
|
+
"",
|
|
109
|
+
' hashedPassword String @default("")',
|
|
110
|
+
' salt String @default("")',
|
|
111
|
+
"",
|
|
112
|
+
"If you expose any of your user data via GraphQL be sure to exclude",
|
|
113
|
+
"`hashedPassword` and `salt` (or whatever you named them) from the",
|
|
114
|
+
"SDL file that defines the fields for your user.",
|
|
115
|
+
"",
|
|
116
|
+
"You'll need to let Cedar know what fields you're using for your users'",
|
|
117
|
+
"`id` and `username` fields. In this case we're using `id` and `email`,",
|
|
118
|
+
"so update those in the `authFields` config in",
|
|
119
|
+
`\`${import_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
|
|
120
|
+
"you used a different name for the `hashedPassword`, `salt`,",
|
|
121
|
+
"`resetToken` or `resetTokenExpiresAt`, fields:`",
|
|
122
|
+
"",
|
|
123
|
+
" authFields: {",
|
|
124
|
+
" id: 'id',",
|
|
125
|
+
" username: 'email',",
|
|
126
|
+
" hashedPassword: 'hashedPassword',",
|
|
127
|
+
" salt: 'salt',",
|
|
128
|
+
" resetToken: 'resetToken',",
|
|
129
|
+
" resetTokenExpiresAt: 'resetTokenExpiresAt',",
|
|
130
|
+
" challenge: 'webAuthnChallenge'",
|
|
131
|
+
" },",
|
|
132
|
+
"",
|
|
133
|
+
"To get the actual user that's logged in, take a look at `getCurrentUser()`",
|
|
134
|
+
`in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
135
|
+
"use different names for your model or unique ID fields, in which case you",
|
|
136
|
+
"need to update those calls (instructions are in the comment above the code).",
|
|
137
|
+
"",
|
|
138
|
+
"Finally, we created a SESSION_SECRET environment variable for you in",
|
|
139
|
+
`${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
|
|
140
|
+
"into version control and should be unique for each environment you",
|
|
141
|
+
"deploy to. If you ever need to log everyone out of your app at once",
|
|
142
|
+
"change this secret to a new value and deploy. To create a new secret, run:",
|
|
143
|
+
"",
|
|
144
|
+
" yarn cedar generate secret",
|
|
145
|
+
""
|
|
146
|
+
];
|
|
147
|
+
const noteGenerate = [
|
|
148
|
+
"",
|
|
149
|
+
"Need simple Login, Signup, Forgot Password pages and WebAuthn prompts?",
|
|
150
|
+
"We've got a generator for those as well:",
|
|
151
|
+
"",
|
|
152
|
+
" yarn cedar generate dbAuth"
|
|
153
|
+
];
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
apiPackages,
|
|
157
|
+
createUserModelTask,
|
|
158
|
+
extraTask,
|
|
159
|
+
noteGenerate,
|
|
160
|
+
notes,
|
|
161
|
+
webPackages
|
|
162
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-dbauth-setup",
|
|
3
|
-
"version": "2.8.1-next.
|
|
3
|
+
"version": "2.8.1-next.109+be993981d",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"build": "yarn build:js && yarn build:types",
|
|
18
|
-
"build:js": "babel src -d dist --extensions \".js,.ts,.snap\" --copy-files --no-copy-ignored",
|
|
16
|
+
"build": "node ./build.mts && yarn build:types",
|
|
19
17
|
"build:pack": "yarn pack -o cedarjs-auth-dbauth-setup.tgz",
|
|
20
18
|
"build:types": "tsc --build --verbose",
|
|
21
19
|
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
|
|
@@ -24,19 +22,17 @@
|
|
|
24
22
|
"test:watch": "yarn test --watch"
|
|
25
23
|
},
|
|
26
24
|
"dependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@simplewebauthn/browser": "9.0.1",
|
|
31
|
-
"core-js": "3.48.0",
|
|
25
|
+
"@cedarjs/cli-helpers": "2.8.1-next.109+be993981d",
|
|
26
|
+
"@prisma/internals": "7.5.0",
|
|
27
|
+
"@simplewebauthn/browser": "10.0.0",
|
|
32
28
|
"prompts": "2.4.2",
|
|
33
29
|
"termi-link": "1.1.0"
|
|
34
30
|
},
|
|
35
31
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@simplewebauthn/types": "9.0.1",
|
|
32
|
+
"@cedarjs/framework-tools": "2.8.1-next.109",
|
|
33
|
+
"@simplewebauthn/types": "10.0.0",
|
|
39
34
|
"@types/yargs": "17.0.35",
|
|
35
|
+
"nodemon": "3.1.14",
|
|
40
36
|
"ts-dedent": "2.2.0",
|
|
41
37
|
"typescript": "5.9.3",
|
|
42
38
|
"vitest": "3.2.4"
|
|
@@ -44,5 +40,5 @@
|
|
|
44
40
|
"publishConfig": {
|
|
45
41
|
"access": "public"
|
|
46
42
|
},
|
|
47
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "be993981d7e162a83244009c3f7ab9270c6773f3"
|
|
48
44
|
}
|