forked from torusresearch/CustomAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup-mode-login.component.ts
87 lines (77 loc) · 2.54 KB
/
popup-mode-login.component.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Component, OnInit } from "@angular/core";
import TorusSdk from "@toruslabs/customauth";
import {
verifierMap,
GOOGLE,
GITHUB,
TWITTER,
APPLE,
AUTH_DOMAIN,
EMAIL_PASSWORD,
HOSTED_EMAIL_PASSWORDLESS,
HOSTED_SMS_PASSWORDLESS,
LINE,
LINKEDIN,
WEIBO,
COGNITO_AUTH_DOMAIN,
COGNITO,
REDDIT,
} from "../../constants/index";
@Component({
selector: "app-popup-mode-login",
templateUrl: "./popup-mode-login.component.html",
styleUrls: ["./popup-mode-login.component.css"],
})
export class PopupModeLoginComponent implements OnInit {
torusdirectsdk = null;
selectedVerifier = GOOGLE;
consoleText = "";
verifierMap = verifierMap;
verifierMapKeys = Object.keys(this.verifierMap);
async ngOnInit() {
try {
const torusdirectsdk = new TorusSdk({
baseUrl: `${location.origin}/serviceworker`,
enableLogging: true,
network: "testnet", // details for test net
});
await torusdirectsdk.init({ skipSw: false });
this.torusdirectsdk = torusdirectsdk;
} catch (error) {
console.error(error, "oninit caught");
}
}
async login() {
try {
const jwtParams = this._loginToConnectionMap()[this.selectedVerifier] || {};
const { typeOfLogin, clientId, verifier } = this.verifierMap[this.selectedVerifier];
const loginDetails = await this.torusdirectsdk.triggerLogin({
typeOfLogin,
verifier,
clientId,
jwtParams,
});
this.consoleText = typeof loginDetails === "object" ? JSON.stringify(loginDetails) : loginDetails;
} catch (error) {
console.error(error, "login caught");
}
}
onSelectedVerifierChanged = (event) => {
this.selectedVerifier = event.target.value;
};
_loginToConnectionMap = () => {
return {
[EMAIL_PASSWORD]: { domain: AUTH_DOMAIN },
[HOSTED_EMAIL_PASSWORDLESS]: { domain: AUTH_DOMAIN, verifierIdField: "name", connection: "", isVerifierIdCaseSensitive: false },
[HOSTED_SMS_PASSWORDLESS]: { domain: AUTH_DOMAIN, verifierIdField: "name", connection: "" },
[APPLE]: { domain: AUTH_DOMAIN },
[GITHUB]: { domain: AUTH_DOMAIN },
[LINKEDIN]: { domain: AUTH_DOMAIN },
[TWITTER]: { domain: AUTH_DOMAIN },
[WEIBO]: { domain: AUTH_DOMAIN },
[LINE]: { domain: AUTH_DOMAIN },
[COGNITO]: { domain: COGNITO_AUTH_DOMAIN, identity_provider: "Google", response_type: "token", user_info_endpoint: "userInfo" },
[REDDIT]: { domain: AUTH_DOMAIN, connection: "Reddit", verifierIdField: "name", isVerifierIdCaseSensitive: false },
};
};
}