Creating a Protected Dashboard
What We Are Doing:
Adding a protected resource (e.g.,
/dashboard) that only verified users can access.Decoding the
access_tokento display user information extracted from the credential.
Why: To show the end result of verification, we will display a dashboard page that uses the credential data.
Steps: Create public/dashboard.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Dashboard</title>
</head>
<body>
<h2>Welcome to the Dashboard!</h2>
<p>DID: <span id="did"></span></p>
<p>First Name: <span id="first-name"></span></p>
<p>Last Name: <span id="last-name"></span></p>
<p>Age: <span id="age"></span></p>
<script>
(async () => {
const token = localStorage.getItem("access_token");
if (!token) return;
const res = await fetch('/authorization/decode-access-token', {
headers: { Authorization: `Bearer ${token}` }
});
const data = await res.json();
document.getElementById("did").innerText = data.did;
document.getElementById("first-name").innerText = data.formData.firstName;
document.getElementById("last-name").innerText = data.formData.lastName;
document.getElementById("age").innerText = data.formData.age;
})();
</script>
</body>
</html>Add a route to decode the token and extract data in src/authorization-routes.js:
Now, after verification, the user is redirected to /dashboard, and their credential info is displayed.
Last updated