29
29
type =" password"
30
30
/>
31
31
32
- <p v-if =" error" class =" text-red-500" >incorrect login or password </p >
32
+ <p v-if =" error" class =" text-red-500" >{{ error }} </p >
33
33
34
34
<p >
35
35
<a
36
+ key =" login-forgot"
36
37
href =" https://home.nanome.ai/login/forgot"
37
38
target =" _blank"
38
39
class =" link text-blue-500"
40
+ >forgot password?</a
39
41
>
40
- forgot password?
42
+ or
43
+
44
+ <a
45
+ key =" login-sso"
46
+ class =" link text-blue-500"
47
+ @click.stop =" options.type = 'login-sso'"
48
+ >log in with SSO</a
49
+ >
50
+ </p >
51
+
52
+ <p ></p >
53
+
54
+ <p class =" text-xs text-gray-700" >
55
+ Don't have a Nanome account?
56
+ <a
57
+ href =" https://home.nanome.ai/register"
58
+ target =" _blank"
59
+ class =" link text-blue-500"
60
+ >
61
+ Register here
62
+ </a >
63
+ </p >
64
+ </template >
65
+
66
+ <template v-else-if =" options .type === ' login-sso' " >
67
+ <input
68
+ ref =" login"
69
+ v-model =" input1"
70
+ :class =" { 'border-red-500': error }"
71
+ placeholder =" email"
72
+ type =" text"
73
+ />
74
+
75
+ <p v-if =" error" class =" text-red-500" >
76
+ {{ error }}
77
+ </p >
78
+
79
+ <p >
80
+ <a
81
+ key =" login-username"
82
+ class =" link text-blue-500"
83
+ @click.stop =" options.type = 'login'"
84
+ >
85
+ log in with username
41
86
</a >
42
87
</p >
43
88
@@ -107,7 +152,7 @@ const deferred = () => {
107
152
export default {
108
153
data : () => ({
109
154
showing: false ,
110
- error: false ,
155
+ error: null ,
111
156
loading: false ,
112
157
options: { ... defaults },
113
158
input1: ' ' ,
@@ -121,14 +166,22 @@ export default {
121
166
122
167
if (this .options .type === ' login' ) {
123
168
return ! this .input1 || ! this .input2
124
- } else if (this .options .type === ' prompt ' ) {
169
+ } else if ([ ' login-sso ' , ' prompt ' ]. includes ( this .options .type ) ) {
125
170
return ! this .input1
126
171
}
127
172
128
173
return false
129
174
}
130
175
},
131
176
177
+ watch: {
178
+ ' options.type' () {
179
+ this .error = null
180
+ this .input1 = ' '
181
+ this .input2 = ' '
182
+ }
183
+ },
184
+
132
185
mounted () {
133
186
document .body .addEventListener (' keydown' , this .onKeydown )
134
187
},
@@ -229,6 +282,9 @@ export default {
229
282
} else if (this .options .type === ' login' ) {
230
283
this .attemptLogin ()
231
284
return
285
+ } else if (this .options .type === ' login-sso' ) {
286
+ this .attemptLoginSSO ()
287
+ return
232
288
}
233
289
234
290
this .deferred .resolve (data)
@@ -237,7 +293,7 @@ export default {
237
293
238
294
async attemptLogin () {
239
295
const deferred = this .deferred
240
- this .error = false
296
+ this .error = null
241
297
242
298
const creds = {
243
299
username: this .input1 ,
@@ -252,6 +308,9 @@ export default {
252
308
break
253
309
} catch (e) {
254
310
this .loading = false
311
+ this .error = e .message
312
+ if (! this .error .includes (' 2FA' )) break
313
+
255
314
creds .tfa_code = await this .prompt ({
256
315
title: ' Enter 2FA code' ,
257
316
body: ' Or use a one time recovery code' ,
@@ -269,8 +328,19 @@ export default {
269
328
if (success) {
270
329
deferred .resolve (true )
271
330
this .reset ()
272
- } else {
273
- this .error = true
331
+ }
332
+ },
333
+
334
+ async attemptLoginSSO () {
335
+ this .error = null
336
+ this .loading = true
337
+
338
+ try {
339
+ const url = await this .$store .dispatch (' loginSSO' , this .input1 )
340
+ window .open (url, ' _self' )
341
+ } catch (e) {
342
+ this .loading = false
343
+ this .error = e .message
274
344
}
275
345
}
276
346
}
0 commit comments