feat: send user data

This commit is contained in:
karishmas6
2024-10-16 21:14:58 +05:30
parent 7b8000101a
commit 0b78e132fb

View File

@@ -168,7 +168,7 @@ router.delete('/delete-api-key', requireSignIn, async (req, res) => {
const oauth2Client = new google.auth.OAuth2( const oauth2Client = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET, process.env.GOOGLE_CLIENT_SECRET,
process.env.GOOGLE_REDIRECT_URI // process.env.GOOGLE_REDIRECT_URI
); );
// Step 1: Redirect to Google for authentication // Step 1: Redirect to Google for authentication
@@ -241,12 +241,18 @@ router.get('/google/callback', async (req, res) => {
const jwtToken = jwt.sign({ userId: user.id }, process.env.JWT_SECRET as string, { expiresIn: '12h' }); const jwtToken = jwt.sign({ userId: user.id }, process.env.JWT_SECRET as string, { expiresIn: '12h' });
res.cookie('token', jwtToken, { httpOnly: true }); res.cookie('token', jwtToken, { httpOnly: true });
res.json({ message: 'Google authentication successful', user, jwtToken, files }); res.json({
message: 'Google authentication successful',
email: user.email,
jwtToken,
files
});
} catch (error: any) { } catch (error: any) {
res.status(500).json({ message: `Google OAuth error: ${error.message}` }); res.status(500).json({ message: `Google OAuth error: ${error.message}` });
} }
}); });
// Step 3: Get data from Google Sheets // Step 3: Get data from Google Sheets
router.post('/gsheets/data', async (req, res) => { router.post('/gsheets/data', async (req, res) => {
const { spreadsheetId } = req.body; const { spreadsheetId } = req.body;