mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* ci(backend-review.yml): add linter step to the backend review workflow * chore(backend-review.yml): remove prettier from lint-action configuration * chore: apply new linting workflow * chore(lint-staged.config.js): reorder lint-staged tasks for JavaScript and TypeScript files * chore(eslint): update ignorePatterns in .eslintrc.js chore(lint-action): remove prettier option in backend-review.yml chore(package.json): add lint and lint:fix scripts * chore(lint-staged.config.js): remove prettier --write command for js, jsx, ts, tsx files * chore(titleConvo.js): remove unnecessary console.log statement chore(titleConvo.js): add missing comma in options object * chore: apply linting to all files * chore(lint-staged.config.js): update lint-staged configuration to include prettier formatting
144 lines
3.2 KiB
JavaScript
144 lines
3.2 KiB
JavaScript
const passport = require('passport');
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
const config = require('../../../config/loader');
|
|
const domains = config.domains;
|
|
const isProduction = config.isProduction;
|
|
|
|
/**
|
|
* Google Routes
|
|
*/
|
|
router.get(
|
|
'/google',
|
|
passport.authenticate('google', {
|
|
scope: ['openid', 'profile', 'email'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/google/callback',
|
|
passport.authenticate('google', {
|
|
failureRedirect: `${domains.client}/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(domains.client);
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/facebook',
|
|
passport.authenticate('facebook', {
|
|
scope: ['public_profile', 'email'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/facebook/callback',
|
|
passport.authenticate('facebook', {
|
|
failureRedirect: `${domains.client}/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(domains.client);
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/openid',
|
|
passport.authenticate('openid', {
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/openid/callback',
|
|
passport.authenticate('openid', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
}),
|
|
(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(domains.client);
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/github',
|
|
passport.authenticate('github', {
|
|
scope: ['user:email', 'read:user'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/github/callback',
|
|
passport.authenticate('github', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
scope: ['user:email', 'read:user'],
|
|
}),
|
|
(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(domains.client);
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/discord',
|
|
passport.authenticate('discord', {
|
|
scope: ['identify', 'email'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/discord/callback',
|
|
passport.authenticate('discord', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
scope: ['identify', '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(domains.client);
|
|
},
|
|
);
|
|
|
|
module.exports = router;
|