diff --git a/README.md b/README.md index 93960fe..90ab8bb 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ w3 up recipies.txt --- -### `w3 login ` +### `w3 login [email]` Authenticate this agent with your email address to get access to all capabilities that had been delegated to it. diff --git a/account.js b/account.js index 1a72d7b..c633912 100644 --- a/account.js +++ b/account.js @@ -5,6 +5,7 @@ import * as Result from '@web3-storage/w3up-client/result' import * as DidMailto from '@web3-storage/did-mailto' import { authorize } from '@web3-storage/capabilities/access' import { base64url } from 'multiformats/bases/base64' +import { select } from '@inquirer/prompts' import { getClient } from './lib.js' import ora from 'ora' @@ -34,9 +35,24 @@ const getGithubOAuthClientID = serviceID => { * @param {boolean} [options.github] */ export const login = async (email, options) => { + let method if (email) { - await loginWithClient(email, await getClient()) + method = 'email' } else if (options?.github) { + method = 'github' + } else { + method = await select({ + message: 'How do you want to login?', + choices: [ + { name: 'Via Email', value: 'email' }, + { name: 'Via GitHub', value: 'github' }, + ], + }) + } + + if (method === 'email' && email) { + await loginWithClient(email, await getClient()) + } else if (method === 'github') { await oauthLoginWithClient(OAuthProviderGitHub, await getClient()) } else { console.error('Error: please provide email address or specify flag for alternate login method')