diff --git a/.changesets/10813.md b/.changesets/10813.md new file mode 100644 index 000000000000..03ac396f8c0b --- /dev/null +++ b/.changesets/10813.md @@ -0,0 +1,5 @@ +- fix(dbAuth): Print the correct "post message" after setup (#10813) by @Tobbe + +After running `yarn rw generate dbAuth` the correct message describing the +needed manual steps is now printed if the user choses to enable WebAuthn +support diff --git a/packages/cli/src/commands/generate/dbAuth/__tests__/dbAuth.test.js b/packages/cli/src/commands/generate/dbAuth/__tests__/dbAuth.test.js index cf7a9a492737..5ae26b7c17d2 100644 --- a/packages/cli/src/commands/generate/dbAuth/__tests__/dbAuth.test.js +++ b/packages/cli/src/commands/generate/dbAuth/__tests__/dbAuth.test.js @@ -186,6 +186,9 @@ describe('dbAuth', () => { it('prompt for webauthn', async () => { let correctPrompt = false + const mockConsoleLog = vi + .spyOn(console, 'log') + .mockImplementation(() => {}) const customEnquirer = new Enquirer({ show: false }) customEnquirer.on('prompt', (prompt) => { @@ -200,6 +203,40 @@ describe('dbAuth', () => { listr2: { silentRendererCondition: true }, }) expect(correctPrompt).toBe(true) + + // Verify that the final log message is not the webauthn one + expect(mockConsoleLog.mock.calls.at(-1)[0]).toMatch( + /Look in LoginPage, Sign/, + ) + mockConsoleLog.mockRestore() + }) + + it('prints webauthn message when answering Yes', async () => { + const mockConsoleLog = vi + .spyOn(console, 'log') + .mockImplementation(() => {}) + + const customEnquirer = new Enquirer() + customEnquirer.on('prompt', (prompt) => { + if (prompt.state.message.includes('Enable WebAuthn')) { + prompt.on('run', () => { + return prompt.keypress('y') + }) + } else { + prompt.submit() + } + }) + + await dbAuth.handler({ + enquirer: customEnquirer, + listr2: { silentRendererCondition: true }, + }) + + // Verify that the final log message is the webauthn one + expect(mockConsoleLog.mock.calls.at(-1)[0]).toMatch( + /In LoginPage, look for the `REDIRECT`/, + ) + mockConsoleLog.mockRestore() }) it('does not prompt for webauthn when flag is given', async () => { diff --git a/packages/cli/src/commands/generate/dbAuth/dbAuth.js b/packages/cli/src/commands/generate/dbAuth/dbAuth.js index f95f929312fe..6e3b3cf7fc58 100644 --- a/packages/cli/src/commands/generate/dbAuth/dbAuth.js +++ b/packages/cli/src/commands/generate/dbAuth/dbAuth.js @@ -320,7 +320,7 @@ const tasks = ({ message: `Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`, default: false, }) - webauthn = response + ctx.webauthn = webauthn = response task.title = `Querying WebAuthn addition: WebAuthn addition${ webauthn ? '' : ' not' } included` @@ -392,8 +392,11 @@ export const handler = async (yargs) => { prepareForRollback(t) } await t.run() + console.log('') - console.log(yargs.webauthn ? WEBAUTHN_POST_INSTALL : POST_INSTALL) + console.log( + yargs.webauthn || t.ctx.webauthn ? WEBAUTHN_POST_INSTALL : POST_INSTALL, + ) } catch (e) { console.log(c.error(e.message)) }