Skip to content

Commit 41eae53

Browse files
author
Alexandra Zwinger
committed
Add unfinishes Logout Button
1 parent 07b0d18 commit 41eae53

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/components/navbar/NavbarButtons.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
1-
import React from "react";
1+
import React, {useEffect, useState} from "react";
22
import "../../styles/navbar.css";
33
import {NavbarComponent} from "./NavbarComponent";
44
import {useLocation} from "react-router-dom";
5+
import LogoutIcon from "@mui/icons-material/Logout";
6+
import {IconButton} from "@mui/material";
7+
import axiosInstance from "../../AxiosConfig";
8+
import {getUser} from "../../api/UserApi";
9+
import {UserDto} from "../../dtos/UserDto";
10+
import keycloak from "../../Keycloak";
511

612
export const NavbarButtons = () => {
13+
const axios = axiosInstance;
14+
const [user, setUser] = useState<UserDto>();
15+
16+
const fetchUser = async () => {
17+
const userData = await getUser(axios);
18+
setUser(userData);
19+
};
20+
21+
useEffect(() => {
22+
fetchUser();
23+
}, [])
24+
25+
const logout = () => {
26+
fetchUser()
27+
if (user?.uuid) {
28+
const keycloakUrl = `http://localhost:7070/realms/study-buddies/users/${user?.uuid}/logout`;
29+
axios.post(keycloakUrl, {}, {
30+
headers: {
31+
Authorization: `Bearer ${keycloak.token}`,
32+
}
33+
});
34+
} else {
35+
console.error("Digga, userId ist undefined.");
36+
}
37+
};
38+
739
return (
840
<>
941
<NavbarComponent
@@ -29,6 +61,10 @@ export const NavbarButtons = () => {
2961
path="/settings"
3062
isActive={IsActive("/settings")}
3163
/>
64+
<span className="navbar-separator sm:p-5 p-0">|</span>
65+
<IconButton onClick={logout}>
66+
<LogoutIcon sx={{fontSize: 15}} className="text-[#949494] hover:text-[#56A095] hover:text-lg"/>
67+
</IconButton>
3268
</>
3369
);
3470
};

0 commit comments

Comments
 (0)