@cedarjs/auth-dbauth-setup 2.3.0 → 2.3.1-next.79

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/setupData.js CHANGED
@@ -21,20 +21,20 @@ const createUserModelTask = exports.createUserModelTask = {
21
21
  }
22
22
  (0, _shared.addModels)(`
23
23
  model User {
24
- id Int @id @default(autoincrement())
24
+ id String @id @default(uuid())
25
25
  email String @unique
26
26
  hashedPassword String
27
27
  salt String
28
28
  resetToken String?
29
29
  resetTokenExpiresAt DateTime?
30
- createdAt DateTime @default(now())
31
- updatedAt DateTime @updatedAt
30
+ createdAt DateTime @default(now())
31
+ updatedAt DateTime @updatedAt
32
32
  }
33
33
  `);
34
34
  }
35
35
  };
36
36
 
37
37
  // any notes to print out when the job is done
38
- const notes = exports.notes = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'You will need to add a couple of fields to your User table in order', 'to store a hashed password and salt:', '', ' model User {', ' id Int @id @default(autoincrement())', ' email String @unique', ' hashedPassword String // <─┐', ' salt String // <─┼─ add these lines', ' resetToken String? // <─┤', ' resetTokenExpiresAt DateTime? // <─┘', ' }', '', 'If you already have existing user records you will need to provide', 'a default value for `hashedPassword` and `salt` or Prisma complains, so', 'change those to: ', '', ' hashedPassword String @default("")', ' salt String @default("")', '', 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "You'll need to let Redwood know what fields you're using for your", "users' `id` and `username` fields. In this case we're using `id` and", '`email`, so update those in the `authFields` config in', `\`${_shared.functionsPath}/auth.js\`. This is also the place to tell Redwood if`, 'you used a different name for the `hashedPassword`, `salt`,', '`resetToken` or `resetTokenExpiresAt`, fields:`', '', ' authFields: {', " id: 'id',", " username: 'email',", " hashedPassword: 'hashedPassword',", " salt: 'salt',", " resetToken: 'resetToken',", " resetTokenExpiresAt: 'resetTokenExpiresAt',", ' },', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', ''];
38
+ const notes = exports.notes = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'You will need to add a couple of fields to your User table in order', 'to store a hashed password and salt:', '', ' model User {', ' id String @id @default(uuid())', ' email String @unique', ' hashedPassword String // <─┐', ' salt String // <─┼─ add these lines', ' resetToken String? // <─┤', ' resetTokenExpiresAt DateTime? // <─┘', ' }', '', 'If you already have existing user records you will need to provide', 'a default value for `hashedPassword` and `salt` or Prisma complains, so', 'change those to: ', '', ' hashedPassword String @default("")', ' salt String @default("")', '', 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "You'll need to let Redwood know what fields you're using for your", "users' `id` and `username` fields. In this case we're using `id` and", '`email`, so update those in the `authFields` config in', `\`${_shared.functionsPath}/auth.js\`. This is also the place to tell Redwood if`, 'you used a different name for the `hashedPassword`, `salt`,', '`resetToken` or `resetTokenExpiresAt`, fields:`', '', ' authFields: {', " id: 'id',", " username: 'email',", " hashedPassword: 'hashedPassword',", " salt: 'salt',", " resetToken: 'resetToken',", " resetTokenExpiresAt: 'resetTokenExpiresAt',", ' },', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', ''];
39
39
  const notesCreatedUserModel = exports.notesCreatedUserModel = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', '', "A new User model was added to your schema. Don't forget to migrate your db", 'before you try using dbAuth:', '', ' yarn cedar prisma migrate dev', ''];
40
40
  const noteGenerate = exports.noteGenerate = ['', "Need simple Login, Signup and Forgot Password pages? We've got a generator", 'for those as well:', '', ' yarn cedar generate dbAuth'];
@@ -13,10 +13,7 @@ export const handler = async (
13
13
  const forgotPasswordOptions: DbAuthHandlerOptions['forgotPassword'] = {
14
14
  // handler() is invoked after verifying that a user was found with the given
15
15
  // username. This is where you can send the user an email with a link to
16
- // reset their password. With the default dbAuth routes and field names, the
17
- // URL to reset the password will be:
18
- //
19
- // https://example.com/reset-password?resetToken=${user.resetToken}
16
+ // reset their password.
20
17
  //
21
18
  // Whatever is returned from this function will be returned from
22
19
  // the `forgotPassword()` function that is destructured from `useAuth()`.
@@ -29,9 +26,12 @@ export const handler = async (
29
26
  // `user` here has been sanitized to only include the fields listed in
30
27
  // `allowedUserFields` so it should be safe to return as-is.
31
28
  handler: (user, _resetToken) => {
32
- // TODO: Send user an email/message with a link to reset their password,
33
- // including the `resetToken`. The URL should look something like:
29
+ // TODO: Send an email/message to the user
30
+ // The message should include a link to reset their password with the
31
+ // `resetToken`. The URL should look something like:
34
32
  // `http://localhost:8910/reset-password?resetToken=${resetToken}`
33
+ // When you implement this, change `_resetToken` to `resetToken` in the
34
+ // function arguments above.
35
35
 
36
36
  return user
37
37
  },
@@ -30,7 +30,7 @@ export const cookieName = 'session_%port%'
30
30
  * seen if someone were to open the Web Inspector in their browser.
31
31
  */
32
32
  export const getCurrentUser = async (session: Decoded) => {
33
- if (!session || typeof session.id !== 'number') {
33
+ if (!session || typeof session.id !== 'string') {
34
34
  throw new Error('Invalid session')
35
35
  }
36
36
 
@@ -33,7 +33,7 @@ const createUserModelTask = exports.createUserModelTask = {
33
33
  }
34
34
  (0, _shared.addModels)(`
35
35
  model User {
36
- id Int @id @default(autoincrement())
36
+ id String @id @default(uuid())
37
37
  email String @unique
38
38
  hashedPassword String
39
39
  salt String
@@ -47,7 +47,7 @@ model User {
47
47
 
48
48
  model UserCredential {
49
49
  id String @id
50
- userId Int
50
+ userId String
51
51
  user User @relation(fields: [userId], references: [id])
52
52
  publicKey Bytes
53
53
  transports String?
@@ -58,5 +58,5 @@ model UserCredential {
58
58
  };
59
59
 
60
60
  // any notes to print out when the job is done
61
- const notes = exports.notes = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'You will need to add a couple of fields to your User table in order', 'to store a hashed password, salt, reset token, and to connect it to', 'a new UserCredential model to keep track of any devices used with', 'WebAuthn authentication:', '', ' model User {', ' id Int @id @default(autoincrement())', ' email String @unique', ' hashedPassword String', ' salt String', ' resetToken String?', ' resetTokenExpiresAt DateTime?', ' webAuthnChallenge String? @unique', ' credentials UserCredential[]', ' }', '', ' model UserCredential {', ' id String @id', ' userId Int', ' user User @relation(fields: [userId], references: [id])', ' publicKey Bytes', ' transports String?', ' counter BigInt', ' }', '', 'If you already have existing user records you will need to provide', 'a default value for `hashedPassword` and `salt` or Prisma complains, so', 'change those to: ', '', ' hashedPassword String @default("")', ' salt String @default("")', '', 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "You'll need to let Redwood know what fields you're using for your", "users' `id` and `username` fields. In this case we're using `id` and", '`email`, so update those in the `authFields` config in', `\`${_shared.functionsPath}/auth.js\`. This is also the place to tell Redwood if`, 'you used a different name for the `hashedPassword`, `salt`,', '`resetToken` or `resetTokenExpiresAt`, fields:`', '', ' authFields: {', " id: 'id',", " username: 'email',", " hashedPassword: 'hashedPassword',", " salt: 'salt',", " resetToken: 'resetToken',", " resetTokenExpiresAt: 'resetTokenExpiresAt',", " challenge: 'webAuthnChallenge'", ' },', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', ''];
61
+ const notes = exports.notes = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'You will need to add a couple of fields to your User table in order', 'to store a hashed password, salt, reset token, and to connect it to', 'a new UserCredential model to keep track of any devices used with', 'WebAuthn authentication:', '', ' model User {', ' id String @id @default(uuid())', ' email String @unique', ' hashedPassword String', ' salt String', ' resetToken String?', ' resetTokenExpiresAt DateTime?', ' webAuthnChallenge String? @unique', ' credentials UserCredential[]', ' }', '', ' model UserCredential {', ' id String @id', ' userId String', ' user User @relation(fields: [userId], references: [id])', ' publicKey Bytes', ' transports String?', ' counter BigInt', ' }', '', 'If you already have existing user records you will need to provide', 'a default value for `hashedPassword` and `salt` or Prisma complains, so', 'change those to: ', '', ' hashedPassword String @default("")', ' salt String @default("")', '', 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "You'll need to let Redwood know what fields you're using for your", "users' `id` and `username` fields. In this case we're using `id` and", '`email`, so update those in the `authFields` config in', `\`${_shared.functionsPath}/auth.js\`. This is also the place to tell Redwood if`, 'you used a different name for the `hashedPassword`, `salt`,', '`resetToken` or `resetTokenExpiresAt`, fields:`', '', ' authFields: {', " id: 'id',", " username: 'email',", " hashedPassword: 'hashedPassword',", " salt: 'salt',", " resetToken: 'resetToken',", " resetTokenExpiresAt: 'resetTokenExpiresAt',", " challenge: 'webAuthnChallenge'", ' },', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', ''];
62
62
  const noteGenerate = exports.noteGenerate = ['', 'Need simple Login, Signup, Forgot Password pages and WebAuthn prompts?', "We've got a generator for those as well:", '', ' yarn cedar generate dbAuth'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/auth-dbauth-setup",
3
- "version": "2.3.0",
3
+ "version": "2.3.1-next.79+a599dc0f9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@babel/runtime-corejs3": "7.28.4",
28
- "@cedarjs/cli-helpers": "2.3.0",
28
+ "@cedarjs/cli-helpers": "2.3.1-next.79+a599dc0f9",
29
29
  "@prisma/internals": "6.19.1",
30
30
  "@simplewebauthn/browser": "9.0.1",
31
31
  "core-js": "3.47.0",
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "510b35f25fcee3577246502a9e1b6f16f5682f9f"
47
+ "gitHead": "a599dc0f911b124b122d1862cabf32635e53540a"
48
48
  }