Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ w3 up recipies.txt

---

### `w3 login <email>`
### `w3 login [email]`

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

Expand Down
18 changes: 17 additions & 1 deletion account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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')
Expand Down
Loading