Update templates/protected.html
Browse files- templates/protected.html +23 -0
templates/protected.html
CHANGED
@@ -10,5 +10,28 @@
|
|
10 |
<body>
|
11 |
<h1>Protected Route</h1>
|
12 |
<p>Welcome, {{user}}!</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
</body>
|
14 |
</html>
|
|
|
10 |
<body>
|
11 |
<h1>Protected Route</h1>
|
12 |
<p>Welcome, {{user}}!</p>
|
13 |
+
<script>
|
14 |
+
function getProtectedResource() {
|
15 |
+
const token = retrieveAccessToken(); // Implement this function to get the stored token
|
16 |
+
fetch('/protected', {
|
17 |
+
headers: {
|
18 |
+
'Authorization': `Bearer ${token}`
|
19 |
+
}
|
20 |
+
})
|
21 |
+
.then(response => {
|
22 |
+
if (!response.ok) {
|
23 |
+
throw new Error('Network response was not ok');
|
24 |
+
}
|
25 |
+
return response.text(); // or response.json() if your server sends JSON
|
26 |
+
})
|
27 |
+
.then(data => {
|
28 |
+
// Handle the protected data
|
29 |
+
console.log(data);
|
30 |
+
})
|
31 |
+
.catch(error => {
|
32 |
+
console.error('Error:', error);
|
33 |
+
});
|
34 |
+
}
|
35 |
+
</script>
|
36 |
</body>
|
37 |
</html>
|