Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds flags to skip prompting of WebAuthn install for headless commands #6022

Merged
merged 14 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dependencies": {
"@babel/runtime-corejs3": "7.16.7",
"@prisma/client": "3.15.2",
"base64url": "3.0.1",
"core-js": "3.23.5",
"cross-undici-fetch": "0.4.14",
"crypto-js": "4.1.1",
Expand All @@ -59,6 +58,7 @@
"@types/split2": "3.2.1",
"@types/uuid": "8.3.4",
"aws-lambda": "1.0.7",
"base64url": "3.0.1",
"jest": "27.5.1",
"split2": "4.1.0",
"typescript": "4.7.4"
Expand Down
29 changes: 20 additions & 9 deletions packages/cli/src/commands/generate/dbAuth/dbAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const builder = (yargs) => {
type: 'boolean',
default: false,
})
.option('webauthn', {
alias: 'w',
default: null,
description: 'Include WebAuthn support (TouchID/FaceID)',
type: 'boolean',
})

.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
Expand Down Expand Up @@ -249,16 +256,20 @@ const tasks = ({
)
}

export const handler = async (options) => {
const response = await prompts({
type: 'confirm',
name: 'answer',
message: `Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`,
initial: false,
})
const webAuthn = response.answer
export const handler = async (yargs) => {
let includeWebAuthn = yargs.webauthn

if (includeWebAuthn === null) {
const response = await prompts({
type: 'confirm',
name: 'answer',
message: `Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`,
initial: false,
})
includeWebAuthn = response.answer
}

const t = tasks({ ...options, webAuthn })
const t = tasks({ ...yargs, webAuthn: includeWebAuthn })

try {
await t.run()
Expand Down
31 changes: 23 additions & 8 deletions packages/cli/src/commands/setup/auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const OUTPUT_PATHS = {
),
}

const WEBAUTHN_SUPPORTED_PROVIDERS = ['dbAuth']

const getWebAppPath = () => getPaths().web.app

const getSupportedProviders = () =>
Expand Down Expand Up @@ -313,6 +315,12 @@ export const builder = (yargs) => {
description: 'Overwrite existing configuration',
type: 'boolean',
})
.option('webauthn', {
alias: 'w',
default: null,
description: 'Include WebAuthn support (TouchID/FaceID)',
type: 'boolean',
})
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
Expand All @@ -324,7 +332,7 @@ export const builder = (yargs) => {
export const handler = async (yargs) => {
const { provider, rwVersion } = yargs
cannikin marked this conversation as resolved.
Show resolved Hide resolved
let force = yargs.force
let webAuthn = false
let includeWebAuthn = yargs.webauthn
dac09 marked this conversation as resolved.
Show resolved Hide resolved
let providerData

// check if api/src/lib/auth.js already exists and if so, ask the user to overwrite
Expand All @@ -344,18 +352,22 @@ export const handler = async (yargs) => {
}

// only dbAuth supports WebAuthn right now, but in theory it could work with
// any provider
if (provider === 'dbAuth') {
// any provider, so we'll do a check here and potentially use any other
// providers webAuthn version of templates
if (
includeWebAuthn === null &&
WEBAUTHN_SUPPORTED_PROVIDERS.includes(provider)
) {
const webAuthnResponse = await prompts({
type: 'confirm',
name: 'answer',
message: `Enable WebAuthn support (TouchID/FaceID)? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`,
initial: false,
})
webAuthn = webAuthnResponse.answer
includeWebAuthn = webAuthnResponse.answer
}

if (webAuthn) {
if (includeWebAuthn) {
providerData = await import(`./providers/${provider}.webAuthn`)
} else {
providerData = await import(`./providers/${provider}`)
Expand All @@ -367,9 +379,12 @@ export const handler = async (yargs) => {
title: 'Generating auth lib...',
task: (_ctx, task) => {
if (apiSrcDoesExist()) {
return writeFilesTask(files({ ...yargs, webAuthn }), {
overwriteExisting: force,
})
return writeFilesTask(
files({ ...yargs, webAuthn: includeWebAuthn }),
{
overwriteExisting: force,
}
)
} else {
task.skip('api/src not found, skipping')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const config = {

// required packages to install
export const webPackages = ['@simplewebauthn/browser']
export const apiPackages = ['@simplewebauthn/server']
export const apiPackages = ['@simplewebauthn/server', 'base64url']
cannikin marked this conversation as resolved.
Show resolved Hide resolved

// any notes to print out when the job is done
export const notes = [
Expand Down
8 changes: 6 additions & 2 deletions tasks/test-project/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async function apiTasks(outputPath, { verbose, linkWithLatestFwBuild }) {

const addDbAuth = async () => {
await execa(
'yarn rw setup auth dbAuth --force',
'yarn rw setup auth dbAuth --force --no-webauthn',
[],
getExecaOptions(outputPath)
)
Expand All @@ -316,7 +316,11 @@ async function apiTasks(outputPath, { verbose, linkWithLatestFwBuild }) {
await execa('yarn rwfw project:copy', [], getExecaOptions(outputPath))
}

await execa('yarn rw g dbAuth', [], getExecaOptions(outputPath))
await execa(
'yarn rw g dbAuth --no-webauthn',
[],
getExecaOptions(outputPath)
)

// add dbAuth User model
const { user } = await import('./codemods/models.js')
Expand Down