Skip to content

Commit bab501b

Browse files
author
Alexandra Zwinger
committed
Finish logout function
1 parent 47bc1c7 commit bab501b

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/components/navbar/NavbarButtons.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,16 @@
1-
import React, {useEffect, useState} from "react";
1+
import React from "react";
22
import "../../styles/navbar.css";
33
import {NavbarComponent} from "./NavbarComponent";
44
import {useLocation} from "react-router-dom";
55
import LogoutIcon from "@mui/icons-material/Logout";
66
import {IconButton} from "@mui/material";
7-
import axiosInstance from "../../AxiosConfig";
8-
import {getUser} from "../../api/UserApi";
9-
import {UserDto} from "../../dtos/UserDto";
107
import keycloak from "../../Keycloak";
118

129
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-
2510
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-
}
11+
keycloak.logout({
12+
redirectUri: 'http://localhost:3000'
13+
});
3714
};
3815

3916
return (

0 commit comments

Comments
 (0)