14 standardize and clean api and fix bruno configuration (#25)
* ADD JWT authentication support with token generation and validation * ADD JWT handling after successful login * ADD user authentication and standardize user retrieval * COMBINE token dtos * ADD JWT authentication filter * IMPROVE token handling * STANDARDIZE API endpoints and improve JWT handling * REMOVE extra logging * REMOVE redundant job existence checks * UPDATE Bruno Google token * REFACTOR some classes * ADD JWT cookie check * ADD AuthProvider and CORS configuration; UPDATE API endpoints for consistency * ADD JWT validation check; * ADD profile picture to database * ADD reload after login to update page * PATCH login issue * REMOVE unused classes * ADJUST logging in JwtFilter * REMOVE unused React component
This commit is contained in:
@@ -2,7 +2,10 @@ import { Menu, X } from 'lucide-react';
|
||||
import MenuButton from "./buttons/MenuButton.tsx";
|
||||
import clsx from "clsx";
|
||||
import type {User} from "../utils/types.ts";
|
||||
import { login } from "../utils/endpoints.ts";
|
||||
import { Dropdown, DropdownItem } from "./Dropdown.tsx";
|
||||
import { GoogleOAuthProvider, GoogleLogin } from '@react-oauth/google';
|
||||
import {useNavigate} from "react-router-dom";
|
||||
|
||||
type props = {
|
||||
sidebarToggled: boolean;
|
||||
@@ -12,9 +15,12 @@ type props = {
|
||||
}
|
||||
|
||||
const Topbar = ({sidebarToggled, setSidebarToggled, user, className}: props) => {
|
||||
const apiUrl = import.meta.env.VITE_API_URL;
|
||||
const loginUrl = `${apiUrl}/oauth2/authorization/google`;
|
||||
const logoutUrl = `${apiUrl}/api/v1/auth/logout`;
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogout = () => {
|
||||
// delete token cookie
|
||||
document.cookie = "token=; Secure; SameSite=None; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={clsx(className, "flex justify-between")}>
|
||||
@@ -26,22 +32,30 @@ const Topbar = ({sidebarToggled, setSidebarToggled, user, className}: props) =>
|
||||
<div>
|
||||
<img
|
||||
className={"w-8 h-8 rounded-full inline-block"}
|
||||
src={user.profilePicture}
|
||||
src={user.profilePictureUrl}
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
|
||||
<Dropdown label={user.name}>
|
||||
<DropdownItem item="Logout"
|
||||
onClick={() => globalThis.location.href = logoutUrl}
|
||||
onClick={() => handleLogout()}
|
||||
className={"text-red-500 font-medium"} />
|
||||
</Dropdown>
|
||||
</div>
|
||||
) :
|
||||
(
|
||||
<MenuButton className={"w-20 text-gray-600"}
|
||||
onClick={() => globalThis.location.href = loginUrl}>
|
||||
Login
|
||||
</MenuButton>
|
||||
<GoogleOAuthProvider
|
||||
clientId={import.meta.env.VITE_GOOGLE_CLIENT_ID}>
|
||||
<GoogleLogin
|
||||
onSuccess={(credentialResponse) => {
|
||||
if (!credentialResponse.credential) {
|
||||
console.error("No credential received from Google Login");
|
||||
return;
|
||||
}
|
||||
login(credentialResponse.credential).then(() => {navigate(0)});
|
||||
}}
|
||||
/>
|
||||
</GoogleOAuthProvider>
|
||||
)}
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user