| 1 | import React, { useMemo } from "react";
|
|---|
| 2 | import { Link, useNavigate } from "react-router-dom";
|
|---|
| 3 |
|
|---|
| 4 | const Dashboard = () => {
|
|---|
| 5 | const navigate = useNavigate();
|
|---|
| 6 |
|
|---|
| 7 | const user = useMemo(() => {
|
|---|
| 8 | try {
|
|---|
| 9 | const raw = localStorage.getItem("authUser");
|
|---|
| 10 | return raw ? JSON.parse(raw) : null;
|
|---|
| 11 | } catch {
|
|---|
| 12 | return null;
|
|---|
| 13 | }
|
|---|
| 14 | }, []);
|
|---|
| 15 |
|
|---|
| 16 | const onLogout = () => {
|
|---|
| 17 | localStorage.removeItem("authToken");
|
|---|
| 18 | localStorage.removeItem("authUser");
|
|---|
| 19 | navigate("/", { replace: true });
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 | return (
|
|---|
| 23 | <div className="min-h-screen p-6">
|
|---|
| 24 | <div className="max-w-3xl mx-auto">
|
|---|
| 25 | <div className="flex items-center justify-between gap-3">
|
|---|
| 26 | <h1 className="text-2xl font-bold">Dashboard</h1>
|
|---|
| 27 | <div className="flex items-center gap-2">
|
|---|
| 28 | <Link className="btn btn-ghost" to="/">
|
|---|
| 29 | Landing
|
|---|
| 30 | </Link>
|
|---|
| 31 | <button className="btn btn-outline" onClick={onLogout}>
|
|---|
| 32 | Logout
|
|---|
| 33 | </button>
|
|---|
| 34 | </div>
|
|---|
| 35 | </div>
|
|---|
| 36 |
|
|---|
| 37 | <div className="mt-6 card bg-base-200 border border-base-300">
|
|---|
| 38 | <div className="card-body">
|
|---|
| 39 | <h2 className="card-title">Account</h2>
|
|---|
| 40 | <div className="text-sm leading-7">
|
|---|
| 41 | <div>
|
|---|
| 42 | <span className="opacity-70">Username:</span>{" "}
|
|---|
| 43 | <span className="font-medium">{user?.username ?? "—"}</span>
|
|---|
| 44 | </div>
|
|---|
| 45 | <div>
|
|---|
| 46 | <span className="opacity-70">Email:</span>{" "}
|
|---|
| 47 | <span className="font-medium">{user?.email ?? "—"}</span>
|
|---|
| 48 | </div>
|
|---|
| 49 | <div>
|
|---|
| 50 | <span className="opacity-70">User ID:</span>{" "}
|
|---|
| 51 | <span className="font-medium">{user?.userId ?? "—"}</span>
|
|---|
| 52 | </div>
|
|---|
| 53 | </div>
|
|---|
| 54 | </div>
|
|---|
| 55 | </div>
|
|---|
| 56 | </div>
|
|---|
| 57 | </div>
|
|---|
| 58 | );
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | export default Dashboard;
|
|---|