mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
![]() |
const passport = require('passport');
|
||
|
const express = require('express');
|
||
|
|
||
|
const router = express.Router();
|
||
|
|
||
|
const isProduction = process.env.NODE_ENV === 'production';
|
||
|
const clientUrl = isProduction ? process.env.CLIENT_URL_PROD : process.env.CLIENT_URL_DEV;
|
||
|
|
||
|
// Social
|
||
|
router.get(
|
||
|
'/google',
|
||
|
passport.authenticate('google', {
|
||
|
scope: ['openid', 'profile', 'email'],
|
||
|
session: false
|
||
|
})
|
||
|
);
|
||
|
|
||
|
router.get(
|
||
|
'/google/callback',
|
||
|
passport.authenticate('google', {
|
||
|
failureRedirect: `${clientUrl}/login`,
|
||
|
failureMessage: true,
|
||
|
session: false,
|
||
|
scope: ['openid', 'profile', 'email']
|
||
|
}),
|
||
|
(req, res) => {
|
||
|
const token = req.user.generateToken();
|
||
|
res.cookie('token', token, {
|
||
|
expires: new Date(Date.now() + eval(process.env.SESSION_EXPIRY)),
|
||
|
httpOnly: false,
|
||
|
secure: isProduction
|
||
|
});
|
||
|
res.redirect(clientUrl);
|
||
|
}
|
||
|
);
|
||
|
|
||
|
router.get(
|
||
|
'/facebook',
|
||
|
passport.authenticate('facebook', {
|
||
|
scope: ['public_profile', 'email'],
|
||
|
session: false
|
||
|
})
|
||
|
);
|
||
|
|
||
|
router.get(
|
||
|
'/facebook/callback',
|
||
|
passport.authenticate('facebook', {
|
||
|
failureRedirect: `${clientUrl}/login`,
|
||
|
failureMessage: true,
|
||
|
session: false,
|
||
|
scope: ['public_profile', 'email']
|
||
|
}),
|
||
|
(req, res) => {
|
||
|
const token = req.user.generateToken();
|
||
|
res.cookie('token', token, {
|
||
|
expires: new Date(Date.now() + eval(process.env.SESSION_EXPIRY)),
|
||
|
httpOnly: false,
|
||
|
secure: isProduction
|
||
|
});
|
||
|
res.redirect(clientUrl);
|
||
|
}
|
||
|
);
|
||
|
|
||
|
module.exports = router;
|