Skip to content

Commit

Permalink
fix(dbAuth): Print the correct "post message" after generation (redwo…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jun 13, 2024
1 parent bfc8eb4 commit 4455a11
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changesets/10813.md
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions packages/cli/src/commands/generate/dbAuth/__tests__/dbAuth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/commands/generate/dbAuth/dbAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 4455a11

Please sign in to comment.