-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathLogin.js
More file actions
146 lines (130 loc) · 5.22 KB
/
Copy pathLogin.js
File metadata and controls
146 lines (130 loc) · 5.22 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { useEffect, useState } from "react";
import { Error } from "../common/Errors";
import { useTranslation } from "react-i18next";
import { useSearchParams } from "react-router-dom";
import clientDetails from "../constants/clientDetails";
import { useExternalScript } from "../hooks/useExternalScript";
import relyingPartyService from "../services/relyingPartyService";
export default function Login({ i18nKeyPrefix = "login" }) {
const { i18n, t } = useTranslation("translation", {
keyPrefix: i18nKeyPrefix,
});
const [searchParams, setSearchParams] = useSearchParams();
const [error, setError] = useState(null);
const signInButtonScript = window._env_.SIGN_IN_BUTTON_PLUGIN_URL;
const state = useExternalScript(signInButtonScript);
useEffect(() => {
const getSearchParams = async () => {
let errorCode = searchParams.get("error");
let error_desc = searchParams.get("error_description");
if (errorCode) {
setError({ errorCode: errorCode, errorMsg: error_desc, showToast: true });
}
};
getSearchParams();
renderSignInButton();
i18n.on("languageChanged", function (lng) {
renderSignInButton();
});
}, [state]);
const renderSignInButton = () => {
const oidcConfig = {
authorizeUri: clientDetails.uibaseUrl + clientDetails.authorizeEndpoint,
redirect_uri: clientDetails.redirect_uri_userprofile,
client_id: clientDetails.clientId,
scope: clientDetails.scopeUserProfile,
nonce: clientDetails.nonce,
state: clientDetails.state,
acr_values: clientDetails.acr_values,
claims_locales: clientDetails.claims_locales,
display: clientDetails.display,
prompt: clientDetails.prompt,
max_age: clientDetails.max_age,
ui_locales: i18n.language,
claims: JSON.parse(decodeURIComponent(clientDetails.userProfileClaims)),
par_callback: relyingPartyService[clientDetails.par_callback_name],
par_callback_timeout: clientDetails.par_callback_timeout,
dpop_callback: relyingPartyService[clientDetails.dpop_callback_name],
code_challenge: relyingPartyService[clientDetails.code_challenge],
};
window.SignInWithEsignetButton?.init({
oidcConfig: oidcConfig,
buttonConfig: {
shape: "soft_edges",
labelText: t("sign_in_with"),
width: "100%"
},
signInElement: document.getElementById("sign-in-with-esignet"),
});
}
const handleLogin = (e) => {
e.preventDefault();
setError({
errorCode: "sign_in_failed",
});
};
return (
<>
<div className="w-full px-20">
<h1 className="w-full text-center title-font sm:text-3xl text-3xl mt-8 mb-8 font-medium text-gray-900">
{t("sign_in_with_health_portal")}
</h1>
<div className="w-full flex mb-6 text-slate-500">
<span className="w-11 inline-flex items-center px-3 text-sm text-gray-900 bg-gray-200 border border-gray-300
ltr:rounded-l-md ltr:border-r-0 rtl:rounded-r-md rtl:border-l-0">
<img src="images/username_icon.png" />
</span>
<input
type="text"
id="user"
className="rounded-none bg-gray-50 border text-gray-900 focus:ring-blue-500 focus:border-blue-500 block flex-1 min-w-0 text-sm border-gray-300 p-2.5
ltr:rounded-r-lg rtl:rounded-l-lg"
placeholder={t("username")}
/>
</div>
<div className="w-full flex mb-6 text-slate-500">
<span className="w-11 inline-flex items-center px-3 text-sm text-gray-900 bg-gray-200 border border-r-0 border-gray-300
ltr:rounded-l-md ltr:border-r-0 rtl:rounded-r-md rtl:border-l-0">
<img src="images/password_icon.png" />
</span>
<input
type="password"
id="password"
className="rounded-none bg-gray-50 border text-gray-900 focus:ring-blue-500 focus:border-blue-500 block flex-1 min-w-0 text-sm border-gray-300 p-2.5
ltr:rounded-r-lg rtl:rounded-l-lg"
placeholder={t("password")}
/>
</div>
<button
type="button"
className="w-full justify-center text-white bg-[#2F8EA3] hover:bg-[#2F8EA3]/90 font-medium rounded-md text-sm px-5 py-2.5 flex items-center mr-2 mb-2 h-11"
onClick={handleLogin}
>
{t("submit")}
</button>
{error && (
<Error errorCode={error.errorCode} errorMsg={error.errorMsg} showToast={error.showToast} />
)}
<div className="flex w-full mb-6 mt-6 items-center px-10">
<div className="flex-1 h-px bg-black" />
<div>
<p className="w-16 text-center">{t("or")}</p>
</div>
<div className="flex-1 h-px bg-black" />
</div>
{state === "ready" && <div id="sign-in-with-esignet" className="w-full"></div>}
<div className="flex flex-justify mt-5 w-full items-center text-center">
<p className="w-full text-center">
{t("dont_have_existing_account")}
<a
href={process.env.PUBLIC_URL + "/signup"}
className="text-[#2F8EA3]"
>
{t("sign_up_here")}
</a>
</p>
</div>
</div>
</>
);
}