Skip to content

Commit c7a14da

Browse files
authored
feat: prompt for login method (#212)
1 parent b8191c9 commit c7a14da

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ w3 up recipies.txt
7272

7373
---
7474

75-
### `w3 login <email>`
75+
### `w3 login [email]`
7676

7777
Authenticate this agent with your email address to get access to all capabilities that had been delegated to it.
7878

account.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Result from '@web3-storage/w3up-client/result'
55
import * as DidMailto from '@web3-storage/did-mailto'
66
import { authorize } from '@web3-storage/capabilities/access'
77
import { base64url } from 'multiformats/bases/base64'
8+
import { select } from '@inquirer/prompts'
89
import { getClient } from './lib.js'
910
import ora from 'ora'
1011

@@ -34,9 +35,24 @@ const getGithubOAuthClientID = serviceID => {
3435
* @param {boolean} [options.github]
3536
*/
3637
export const login = async (email, options) => {
38+
let method
3739
if (email) {
38-
await loginWithClient(email, await getClient())
40+
method = 'email'
3941
} else if (options?.github) {
42+
method = 'github'
43+
} else {
44+
method = await select({
45+
message: 'How do you want to login?',
46+
choices: [
47+
{ name: 'Via Email', value: 'email' },
48+
{ name: 'Via GitHub', value: 'github' },
49+
],
50+
})
51+
}
52+
53+
if (method === 'email' && email) {
54+
await loginWithClient(email, await getClient())
55+
} else if (method === 'github') {
4056
await oauthLoginWithClient(OAuthProviderGitHub, await getClient())
4157
} else {
4258
console.error('Error: please provide email address or specify flag for alternate login method')

0 commit comments

Comments
 (0)