diff --git a/client_web/src/Config/backend.routes.ts b/client_web/src/Config/backend.routes.ts index f1165bc..8e1b7e4 100644 --- a/client_web/src/Config/backend.routes.ts +++ b/client_web/src/Config/backend.routes.ts @@ -42,6 +42,10 @@ const auth = { health: `${endpoint}/auth/health`, } +const oauth = { + microsoft: `${endpoint}/oauth/microsoft`, +} + const workflow = { create: `${endpoint}/workflow/create`, } @@ -51,5 +55,6 @@ export { instanceWithAuth, root, auth, + oauth, workflow } diff --git a/client_web/src/Pages/Auth/Forms/Register.tsx b/client_web/src/Pages/Auth/Forms/Register.tsx index 528aab9..443f6d1 100644 --- a/client_web/src/Pages/Auth/Forms/Register.tsx +++ b/client_web/src/Pages/Auth/Forms/Register.tsx @@ -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"; @@ -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) => {