20260607 - login, add scene, add hotspot
This commit is contained in:
@@ -6,9 +6,14 @@ const User = require('../models/User');
|
||||
*/
|
||||
const protect = async (req, res, next) => {
|
||||
let token;
|
||||
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer')) {
|
||||
if (
|
||||
(req.headers.authorization && req.headers.authorization.startsWith('Bearer')) ||
|
||||
req.query.token
|
||||
) {
|
||||
try {
|
||||
token = req.headers.authorization.split(' ')[1];
|
||||
token = req.headers.authorization
|
||||
? req.headers.authorization.split(' ')[1]
|
||||
: req.query.token;
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||
req.user = await User.findById(decoded.id).select('-password');
|
||||
if (!req.user) {
|
||||
@@ -28,9 +33,14 @@ const protect = async (req, res, next) => {
|
||||
* but allows the request to proceed as a guest if no token is found.
|
||||
*/
|
||||
const optionalAuth = async (req, res, next) => {
|
||||
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer')) {
|
||||
if (
|
||||
(req.headers.authorization && req.headers.authorization.startsWith('Bearer')) ||
|
||||
req.query.token
|
||||
) {
|
||||
try {
|
||||
const token = req.headers.authorization.split(' ')[1];
|
||||
const token = req.headers.authorization
|
||||
? req.headers.authorization.split(' ')[1]
|
||||
: req.query.token;
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||
req.user = await User.findById(decoded.id).select('-password');
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user