-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathmultiFactor.js
46 lines (39 loc) · 1.36 KB
/
multiFactor.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
/**
* Return a MultiFactorUser instance the gateway to multi-factor operations.
*/
export function multiFactor(auth) {
// eslint-disable-next-line no-console
console.warn('This method is deprecated. Please use auth().multiFactor(user) instead');
return new MultiFactorUser(auth);
}
export class MultiFactorUser {
constructor(auth, user) {
this._auth = auth;
if (user === undefined) {
user = auth.currentUser;
}
this._user = user;
this.enrolledFactor = user.multiFactor.enrolledFactors;
}
getSession() {
return this._auth.native.getSession();
}
/**
* Finalize the enrollment process for the given multi-factor assertion.
* Optionally set a displayName. This method will reload the current user
* profile, which is necessary to see the multi-factor changes.
*/
async enroll(multiFactorAssertion, displayName) {
const { token, secret } = multiFactorAssertion;
await this._auth.native.finalizeMultiFactorEnrollment(token, secret, displayName);
// We need to reload the user otherwise the changes are not visible
return this._auth.currentUser.reload();
}
async enrollTotp(verificationCode, displayName) {
await this._auth.native.enrollTotp(verificationCode, displayName);
return this._auth.currentUser.reload();
}
unenroll() {
return Promise.reject(new Error('No implemented yet.'));
}
}