Skip to content

Commit

Permalink
wip(wip): wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mael-RABOT <[email protected]>
  • Loading branch information
Mael-RABOT committed Dec 9, 2024
1 parent 42d5d45 commit 65c34b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions client_web/src/Config/backend.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const auth = {
health: `${endpoint}/auth/health`,
}

const oauth = {
microsoft: `${endpoint}/oauth/microsoft`,
}

const workflow = {
create: `${endpoint}/workflow/create`,
}
Expand All @@ -51,5 +55,6 @@ export {
instanceWithAuth,
root,
auth,
oauth,
workflow
}
25 changes: 23 additions & 2 deletions client_web/src/Pages/Auth/Forms/Register.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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";
Expand Down Expand Up @@ -46,11 +46,32 @@ const Register = () => {

const handleMicrosoftSuccess = (response: unknown) => {
console.log('Microsoft Register Success:', response);
// Call your API to verify the Microsoft token and register 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 Register Failed:', error);
// @ts-expect-error error isn't typed
toast.error('Failed to register: ' + error?.response?.data?.error);
};

const handleLinkedinSuccess = (response: unknown) => {
Expand Down

0 comments on commit 65c34b1

Please sign in to comment.