Skip to content

Commit

Permalink
feat: oauth complete
Browse files Browse the repository at this point in the history
  • Loading branch information
harshkhandeparkar committed Sep 18, 2024
1 parent e1a53ac commit f1265c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 9 additions & 3 deletions frontend/src/pages/OAuthPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ export default function OAuthPage() {
const auth = useAuthContext();
const navigate = useNavigate();
const [message, setMessage] = useState<string>("Authenticating, please wait...");
const [awaitingResponse, setAwaitingRepsonse] = useState<boolean>(false);

const loginHandler = async (code: string) => {
console.log("handleraddo", code)
const response = await makeRequest('oauth', 'post', { code });
console.log("handleraddo", response)

if (response.status === 'success') {
if ("token" in response.data) {
Expand All @@ -23,6 +26,8 @@ export default function OAuthPage() {
} else {
setMessage("Authentication failed due to a server error. Please try again later.");
}

setAwaitingRepsonse(false);
}

useEffect(() => {
Expand All @@ -34,16 +39,17 @@ export default function OAuthPage() {
if (urlParams.get("code") === null) {
setMessage("No OAuth code found. Redirecting to home page in 5s.");
setTimeout(() => navigate("/"), 5000);
} else {
} else if (!awaitingResponse) {
setAwaitingRepsonse(true);
loginHandler(urlParams.get("code") as string);
}
}
}, [])
}, []);

return (
<Header
title="Admin OAuth"
subtitle={message}
subtitle={awaitingResponse ? "Authenticating with the server, please wait." : message}
/>
)
}
3 changes: 1 addition & 2 deletions frontend/src/utils/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
);

const login = (jwt: string) => {
setIsAuthenticated(true);
localStorage.setItem("jwt", jwt);
setIsAuthenticated(true);
};

const logout = () => {
localStorage.removeItem("jwt");

setIsAuthenticated(false);
};

Expand Down

0 comments on commit f1265c8

Please sign in to comment.