This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
/
auth.js
59 lines (46 loc) · 1.55 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const {flags} = require('@oclif/command')
const Command = require('../../command-base')
const WordupAPI = require('../../lib/api')
class AuthCommand extends Command {
async run() {
const {flags} = this.parse(AuthCommand)
/*const wordupOauth = new OAuth(this.config.configDir)
const isAuth = await wordupOauth.isAuthenticated()
if (!isAuth) {
wordupOauth.authFlow()
} else if (flags.logout) {
wordupOauth.logout()
} else {
this.log('Wordup ist already connected. If you want to authenticate with a different account. Use --logout')
}*/
const api = new WordupAPI(this.wordupConfig)
if(flags.logout){
api.oauth.logout()
}else {
const userToken = this.getUserAuthToken()
if(!userToken){
this.log('INFO: You need to have a Wordup account to authenticate.')
this.log("Visit https://console.wordup.dev if you don't have an account.")
this.log('')
api.oauth.authFlow()
} else {
//Get user profile
try {
const response = await api.userProfile()
const data = response.data
this.log('Already logged in as '+data.email_fb+'. Use the --logout flag if you want to logout.')
}catch(error){
this.error(error.message)
}
}
}
}
}
AuthCommand.description = `Authenticate the CLI with your wordup account
...
You will be redirect to the wordup.dev page.
`
AuthCommand.flags = {
logout: flags.boolean({char: 'l', description: 'Logout of your account'}),
}
module.exports = AuthCommand