diff --git a/OAuth2-Backend-Approach.md b/OAuth2-Backend-Approach.md index a57c492..e3d5ea8 100644 --- a/OAuth2-Backend-Approach.md +++ b/OAuth2-Backend-Approach.md @@ -245,7 +245,7 @@ curl -X GET "https://www.googleapis.com/oauth2/v3/userinfo" \ } ``` -### Frontend Code +### Frontend Dashboard Code ```js 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' }); + } +}); +```