Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu <[email protected]>
  • Loading branch information
mathieu-brl committed Dec 9, 2024
1 parent 755c434 commit 9dc840e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 23 additions & 5 deletions client_web/src/Pages/Auth/Forms/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Form, Input, Button, Card } from 'antd';
import { Link } from 'react-router-dom';
import OAuthButtons from '../../../Components/Auth/OAuthButtons';
import { instance, auth } from "@Config/backend.routes";
import { instance, auth, oauth } from "@Config/backend.routes";
import { useAuth } from "@/Context/ContextHooks";
import { useNavigate } from 'react-router-dom';
import {toast} from "react-toastify";
import { toast } from "react-toastify";

const Login = () => {
const { setJsonWebToken, isAuthenticated, setIsAuthenticated } = useAuth();
Expand Down Expand Up @@ -43,10 +43,28 @@ const Login = () => {
};

const handleMicrosoftSuccess = (response: unknown) => {
console.log('Microsoft Login Success:', response);
// Call your API to verify the Microsoft token and log in the user
// @ts-expect-error response isn't typed
instance.post(oauth.microsoft, { "token": response?.accessToken }, {
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => {
if (!response?.data?.jwt) {
console.error('JWT not found in response');
return;
}
localStorage.setItem('jsonWebToken', response?.data?.jwt);
setJsonWebToken(response?.data?.jwt);
setIsAuthenticated(true);
navigate('/dashboard');
})
.catch((error) => {
console.error('Failed:', error);
toast.error('Failed to register: ' + (error?.response?.data?.error || 'Network error'));
});
};

const handleMicrosoftError = (error: unknown) => {
console.error('Microsoft Login Failed:', error);
};
Expand Down
1 change: 0 additions & 1 deletion client_web/src/Pages/Auth/Forms/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const Register = () => {
};

const handleMicrosoftSuccess = (response: unknown) => {
console.log('Microsoft Register Success:', response);
// @ts-expect-error response isn't typed
instance.post(oauth.microsoft, { "token": response?.accessToken }, {
headers: {
Expand Down

0 comments on commit 9dc840e

Please sign in to comment.