Skip to content

Commit 964f763

Browse files
committed
added support for the auth2 providers
1 parent 423d240 commit 964f763

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

frontend/app/account/login/page.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ import styles from "./login-form.module.scss";
44
import authService from "@/services/auth.service";
55
import * as Yup from "yup";
66
import { useRouter } from "next/navigation";
7-
import { useRef, useState } from "react";
7+
import { useEffect, useRef, useState } from "react";
8+
import userApi from "@api/userApi";
89

10+
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
11+
const AUTH_ENDPOINT = SERVER_URL + "/";
912
export interface Credentials {
1013
username: string;
1114
password: string;
1215
}
1316

17+
interface Oauth2Sources {
18+
provider: string;
19+
iconUrl: string;
20+
authEndpoint: string;
21+
}
22+
1423
function failureMessage(submitMessage: string) {
1524
return submitFailureDisplay(submitMessage);
1625
}
@@ -22,7 +31,16 @@ function submitFailureDisplay(submissionMessage: string) {
2231
export default function Page() {
2332
const [signinFailure, setSigninFailure] = useState<boolean>(false);
2433
const attemptCount = useRef<number>(0);
34+
const [oauth2Providers, setOauth2Provider] = useState<Oauth2Sources[]>([]);
2535
const router = useRouter();
36+
37+
useEffect(() => {
38+
userApi.oauth2Providers().then((resp) => {
39+
console.log(resp.data);
40+
setOauth2Provider(resp.data as Oauth2Sources[]);
41+
});
42+
}, []);
43+
2644
const handleOnSubmit = async (credentials: Credentials) => {
2745
if (await authService.login(credentials)) {
2846
attemptCount.current = 0;
@@ -96,7 +114,35 @@ export default function Page() {
96114
</Form>
97115
)}
98116
</Formik>
117+
{oauth2Providers ? (
118+
<div className={styles.oauth}>
119+
<h4>
120+
<i>or login with:</i>
121+
</h4>
122+
<ul className={`list-group list-group-flush `}>
123+
{oauth2Providers.map((oauth, index) => (
124+
<a
125+
href={AUTH_ENDPOINT + oauth.authEndpoint}
126+
target="_self"
127+
key={index}
128+
className="list-group-item rounded"
129+
>
130+
{oauth.provider}
131+
<span className="float-end">
132+
<img
133+
src={oauth.iconUrl}
134+
alt={`${oauth.provider} icon`}
135+
style={{ width: 25, height: 25, marginRight: 10 }}
136+
/>
137+
</span>
138+
</a>
139+
))}
140+
</ul>
141+
</div>
142+
) : null}
99143
</div>
100144
</div>
101145
);
102146
}
147+
148+
// src={oauth.iconUrl}

0 commit comments

Comments
 (0)