-
-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathDashboard.js
39 lines (37 loc) · 1.05 KB
/
Dashboard.js
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
import React, { useState } from "react";
import { Card, Button, Alert } from "react-bootstrap";
import { useAuth } from "../contexts/AuthContext";
import { Link, useNavigate } from "react-router-dom";
export default function Dashboard() {
const { currentUser, logout } = useAuth();
const [error, setError] = useState("");
const navigate = useNavigate();
async function handleLogout() {
setError("");
try {
await logout();
navigate("/login");
} catch {
setError("Failed to logout");
}
}
return (
<>
<Card>
<Card.Body>
<h2 className="text-center mb-4">Profile</h2>
{error && <Alert variant="danger">{error}</Alert>}
<strong>Email: </strong> {currentUser?.email}
<Link to="/update-profile" className="btn btn-primary w-100 mt-3">
Update Profile
</Link>
</Card.Body>
</Card>
<div className="w-100 text-center mt-2">
<Button variant="link" onClick={handleLogout}>
Log Out
</Button>
</div>
</>
);
}