diff --git a/packages/auth-providers/dbAuth/setup/src/__tests__/setup.test.ts b/packages/auth-providers/dbAuth/setup/src/__tests__/setup.test.ts index 7d6b90b386f6..d8cf340501f6 100644 --- a/packages/auth-providers/dbAuth/setup/src/__tests__/setup.test.ts +++ b/packages/auth-providers/dbAuth/setup/src/__tests__/setup.test.ts @@ -315,5 +315,95 @@ export const handler = createGraphQLHandler({ ) }) }) + + describe('db migration hint', () => { + it('is not included if no db model was created', async () => { + const packageJsonPath = path.resolve(__dirname, '../../package.json') + + vol.fromJSON( + { + [packageJsonPath]: '{ "version": "0.0.0" }', + }, + redwoodProjectPath, + ) + + await handler({ + webauthn: false, + createUserModel: false, + generateAuthPages: true, + force: false, + }) + + expect(jest.mocked(console).log.mock.calls[0][0]).not.toContain( + 'yarn rw prisma migrate dev', + ) + }) + + it('is not included for WebAuthn if no db model was created', async () => { + const packageJsonPath = path.resolve(__dirname, '../../package.json') + + vol.fromJSON( + { + [packageJsonPath]: '{ "version": "0.0.0" }', + }, + redwoodProjectPath, + ) + + await handler({ + webauthn: true, + createUserModel: false, + generateAuthPages: true, + force: false, + }) + + expect(jest.mocked(console).log.mock.calls[0][0]).not.toContain( + 'yarn rw prisma migrate dev', + ) + }) + + it('is included if db model was created', async () => { + const packageJsonPath = path.resolve(__dirname, '../../package.json') + + vol.fromJSON( + { + [packageJsonPath]: '{ "version": "0.0.0" }', + }, + redwoodProjectPath, + ) + + await handler({ + webauthn: false, + createUserModel: true, + generateAuthPages: true, + force: false, + }) + + expect(jest.mocked(console).log.mock.calls[0][0]).toContain( + 'yarn rw prisma migrate dev', + ) + }) + + it('is included if db model was created', async () => { + const packageJsonPath = path.resolve(__dirname, '../../package.json') + + vol.fromJSON( + { + [packageJsonPath]: '{ "version": "0.0.0" }', + }, + redwoodProjectPath, + ) + + await handler({ + webauthn: false, + createUserModel: true, + generateAuthPages: true, + force: false, + }) + + expect(jest.mocked(console).log.mock.calls[0][0]).toContain( + 'yarn rw prisma migrate dev', + ) + }) + }) }) }) diff --git a/packages/auth-providers/dbAuth/setup/src/setupData.ts b/packages/auth-providers/dbAuth/setup/src/setupData.ts index 4ae8fabcfbae..0ecf0052fc59 100644 --- a/packages/auth-providers/dbAuth/setup/src/setupData.ts +++ b/packages/auth-providers/dbAuth/setup/src/setupData.ts @@ -92,13 +92,14 @@ export const notes = [ 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn rw generate secret', + '', ] export const notesCreatedUserModel = [ `${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` from the SDL file that defines the', - 'fields for your user.', + '`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 \`${libPath}/auth.js\`. We default it to something simple, but you may`, @@ -112,6 +113,12 @@ export const notesCreatedUserModel = [ 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn rw generate secret', + '', + "A new User model was added to your schema. Don't forget to migrate your db", + 'before you try using dbAuth:', + '', + ' yarn rw prisma migrate dev', + '', ] export const noteGenerate = [ diff --git a/packages/auth-providers/dbAuth/setup/src/setupHandler.ts b/packages/auth-providers/dbAuth/setup/src/setupHandler.ts index 05a058428122..4166a6fba4b5 100644 --- a/packages/auth-providers/dbAuth/setup/src/setupHandler.ts +++ b/packages/auth-providers/dbAuth/setup/src/setupHandler.ts @@ -22,7 +22,6 @@ import { import { notes as webAuthnNotes, noteGenerate as webAuthnNoteGenerate, - notesCreatedUserModel as webAuthnNotesCreatedUserModel, extraTask as webAuthnExtraTask, webPackages as webAuthnWebPackages, apiPackages as webAuthnApiPackages, @@ -47,7 +46,7 @@ export async function handler({ if (webAuthn) { if (createDbUserModel) { - oneMoreThing.push(...webAuthnNotesCreatedUserModel) + oneMoreThing.push(...notesCreatedUserModel) } else { oneMoreThing.push(...webAuthnNotes) } diff --git a/packages/auth-providers/dbAuth/setup/src/webAuthn.setupData.ts b/packages/auth-providers/dbAuth/setup/src/webAuthn.setupData.ts index c1c14645c814..3fd3ada8a29b 100644 --- a/packages/auth-providers/dbAuth/setup/src/webAuthn.setupData.ts +++ b/packages/auth-providers/dbAuth/setup/src/webAuthn.setupData.ts @@ -117,29 +117,7 @@ export const notes = [ 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn rw generate secret', -] - -// Only thing different here compared to the notes for when *not* setting up -// webauthn is the very end where we hint about adding pages for WebAuthn -// prompts -export const notesCreatedUserModel = [ - `${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 \`${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.join(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 rw generate secret', ] export const noteGenerate = [