Update OAuth2-Backend-Approach.md
This commit is contained in:
parent
d393509b1c
commit
35950a209b
@ -245,7 +245,7 @@ curl -X GET "https://www.googleapis.com/oauth2/v3/userinfo" \
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Frontend Code
|
### Frontend Dashboard Code
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
@ -301,3 +301,24 @@ function DashboardPage() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Backend Dashboard
|
||||||
|
|
||||||
|
```js
|
||||||
|
app.get('/api/dashboard-data', (req, res) => {
|
||||||
|
// The auth cookie is automatically included in req.cookies
|
||||||
|
const authToken = req.cookies.auth_token;
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
return res.status(401).json({ error: 'Not authenticated' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the token and get data in one go
|
||||||
|
try {
|
||||||
|
// verify token...
|
||||||
|
// get dashboard data...
|
||||||
|
res.json({ dashboardData: 'your data here' });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(401).json({ error: 'Invalid token' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user