main
|
Last change
on this file since 24a2a2a was 24a2a2a, checked in by Filip Gavrilovski <filipgavrilovski28@…>, 6 months ago |
|
add login page
|
-
Property mode
set to
100644
|
|
File size:
2.0 KB
|
| Rev | Line | |
|---|
| [24a2a2a] | 1 | import { Link } from "react-router-dom";
|
|---|
| 2 | import axiosInstance from "./api/axiosInstance";
|
|---|
| 3 | import { useAuth } from "./context/authContext";
|
|---|
| 4 |
|
|---|
| 5 | const Nav = () => {
|
|---|
| 6 | const { user, setUser, isAuthLoading } = useAuth();
|
|---|
| 7 |
|
|---|
| 8 | const handleLogout = async () => {
|
|---|
| 9 | try {
|
|---|
| 10 | await axiosInstance.post("/auth/logout");
|
|---|
| 11 | setUser(undefined);
|
|---|
| 12 | } catch (error) {
|
|---|
| 13 | console.error("Logout failed:", error);
|
|---|
| 14 | }
|
|---|
| 15 | };
|
|---|
| 16 |
|
|---|
| 17 | return (
|
|---|
| 18 | <div className="bg-gray-800 p-4 flex justify-between items-center">
|
|---|
| 19 | <Link to="/" className="text-white text-lg font-semibold">
|
|---|
| 20 | Finkwave
|
|---|
| 21 | </Link>
|
|---|
| 22 |
|
|---|
| 23 | <div className="flex items-center space-x-4">
|
|---|
| 24 | {!isAuthLoading && (
|
|---|
| 25 | <div className="flex items-center space-x-3">
|
|---|
| 26 | {user ? (
|
|---|
| 27 | <div className="flex items-center space-x-3">
|
|---|
| 28 | <div className="flex items-center space-x-2 bg-slate-700 rounded-lg px-3 py-2">
|
|---|
| 29 | <div className="w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center">
|
|---|
| 30 | <span className="text-white text-sm font-semibold">
|
|---|
| 31 | {user.username.charAt(0).toUpperCase()}
|
|---|
| 32 | </span>
|
|---|
| 33 | </div>
|
|---|
| 34 | <div className="text-white">
|
|---|
| 35 | <p className="text-sm font-medium">{user.username}</p>
|
|---|
| 36 | <p className="text-xs text-gray-300 capitalize">
|
|---|
| 37 | {user.role}
|
|---|
| 38 | </p>
|
|---|
| 39 | </div>
|
|---|
| 40 | </div>
|
|---|
| 41 | <button
|
|---|
| 42 | onClick={(e) => {
|
|---|
| 43 | e.preventDefault();
|
|---|
| 44 | handleLogout();
|
|---|
| 45 | }}
|
|---|
| 46 | className="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors duration-200 flex items-center space-x-1"
|
|---|
| 47 | >
|
|---|
| 48 | Logout
|
|---|
| 49 | </button>
|
|---|
| 50 | </div>
|
|---|
| 51 | ) : (
|
|---|
| 52 | <div className="flex items-center space-x-2">
|
|---|
| 53 | <Link
|
|---|
| 54 | to="/login"
|
|---|
| 55 | className="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors duration-200"
|
|---|
| 56 | >
|
|---|
| 57 | Login
|
|---|
| 58 | </Link>
|
|---|
| 59 | </div>
|
|---|
| 60 | )}
|
|---|
| 61 | </div>
|
|---|
| 62 | )}
|
|---|
| 63 | </div>
|
|---|
| 64 | </div>
|
|---|
| 65 | );
|
|---|
| 66 | };
|
|---|
| 67 |
|
|---|
| 68 | export default Nav;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.