mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
feat: add sample multi-user support
feat: update README
This commit is contained in:
parent
41f351786f
commit
62d88380e0
19 changed files with 314 additions and 49 deletions
46
api/server/routes/auth.js
Normal file
46
api/server/routes/auth.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const authYourLogin = require('./authYourLogin');
|
||||
const userSystemEnabled = process.env.ENABLE_USER_SYSTEM || false
|
||||
|
||||
router.get('/login', function (req, res) {
|
||||
if (userSystemEnabled)
|
||||
res.redirect('/auth/your_login_page')
|
||||
else
|
||||
res.redirect('/')
|
||||
})
|
||||
|
||||
router.get('/logout', function (req, res) {
|
||||
// clear the session
|
||||
req.session.user = null
|
||||
|
||||
req.session.save(function (error) {
|
||||
if (userSystemEnabled)
|
||||
res.redirect('/auth/your_login_page/logout')
|
||||
else
|
||||
res.redirect('/')
|
||||
})
|
||||
})
|
||||
|
||||
const authenticatedOr401 = (req, res, next) => {
|
||||
if (userSystemEnabled) {
|
||||
const user = req?.session?.user;
|
||||
|
||||
if (user) next();
|
||||
else res.status(401).end();
|
||||
} else next();
|
||||
}
|
||||
|
||||
const authenticatedOrRedirect = (req, res, next) => {
|
||||
if (userSystemEnabled) {
|
||||
const user = req?.session?.user;
|
||||
|
||||
if (user) next();
|
||||
else res.redirect('/auth/login').end();
|
||||
} else next();
|
||||
}
|
||||
|
||||
if (userSystemEnabled)
|
||||
router.use('/your_login_page', authYourLogin);
|
||||
|
||||
module.exports = { router, authenticatedOr401, authenticatedOrRedirect };
|
Loading…
Add table
Add a link
Reference in a new issue