File size: 1,056 Bytes
1bc6bd1 f01b61f 1bc6bd1 ea435f2 9713743 29a625a 9713743 1bc6bd1 3efb9ac |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Protected Route</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Protected Route</h1>
<p>Welcome, {{user}}!</p>
<script>
function retrieveAccessToken() {
return localStorage.getItem("access_token");
}
function getProtectedResource() {
const token = retrieveAccessToken(); // Implement this function to get the stored token
fetch('/protected', {
headers: {
'Authorization': `Bearer ${token}`
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text(); // or response.json() if your server sends JSON
})
.then(data => {
// Handle the protected data
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
}
</script>
</body>
</html> |