File size: 2,597 Bytes
5649a75
784b5c6
5649a75
2ea6bf5
92f01f5
e71a2ef
 
5649a75
 
 
b780a2e
2ea6bf5
5649a75
 
 
 
 
b780a2e
5649a75
 
 
 
 
 
b780a2e
5649a75
 
 
 
 
 
 
2ea6bf5
5649a75
 
 
 
 
 
 
e71a2ef
fced295
784b5c6
b780a2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e71a2ef
784b5c6
fced295
e71a2ef
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use client';

import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import NexusAuthApi from "@lib/Nexus_Auth_API";

export default function Home() {
  const [username, setUsername] = useState(null);
  const [userID, setUserID] = useState(null);
  const [token, setToken] = useState(null);
  const [accessLevel, setAccessLevel] = useState(null);
  const router = useRouter();

  useEffect(() => {
    setUsername(localStorage.getItem('me'));
    setUserID(localStorage.getItem('u_id'));
    setToken(localStorage.getItem('s_tkn'));
    setAccessLevel(localStorage.getItem('a_l'));
  }, []);

  const clearLocalStorage = () => {
    localStorage.removeItem('me');
    localStorage.removeItem('s_tkn');
    localStorage.removeItem('u_id');
    localStorage.removeItem('a_l');
    setUsername(null);
  };

  const handleLogout = () => {
    NexusAuthApi.logout(userID, token)
      .then(() => {
        clearLocalStorage();
        router.push('/');
        window.location.reload();
      })
      .catch((error) => {
        console.error("Logout failed", error);
      });
  };

  return (
    <div className="page-content">
      {username && (
        <div className="max-w-sm mx-auto shadow-lg rounded-lg overflow-hidden bg-gray-800 text-white">
          <table className="min-w-full divide-y divide-gray-700">
            <tbody className="divide-y divide-gray-700">
              <tr>
                <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">User ID:</td>
                <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-100"><strong>{userID}</strong></td>
              </tr>
              <tr>
                <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">Username:</td>
                <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-100"><strong>{username}</strong></td>
              </tr>

              <tr>
                <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">Access Level:</td>
                <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-100"><strong>{accessLevel}</strong></td>
              </tr>
              <tr>
                <td colSpan="2" className="px-6 py-4 whitespace-nowrap text-sm text-center">
                  <button onClick={handleLogout} className="bg-red-600 text-white px-4 py-2 rounded-md hover:bg-red-700 transition duration-300">Logout</button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      )}
    </div>
  );
}