temp
This commit is contained in:
@@ -23,12 +23,12 @@
|
||||
"build": "NODE_ENV=production bun bun.config.mjs",
|
||||
"postbuild": "ev pack",
|
||||
"deploy": "rsync -avz --delete ./pack-dist/ light:/root/kevisual/assistant-app/apps/root/code-center",
|
||||
"deploy:envision": "rsync -avz --delete ./pack-dist/ envision:~/kevisual/assistant-app/apps/root/code-center",
|
||||
"deploy:kevisual": "rsync -avz --delete ./pack-dist/ kevisual:~/kevisual/assistant-app/apps/root/code-center",
|
||||
"clean": "rm -rf dist",
|
||||
"reload": "ssh light pm2 restart root/code-center",
|
||||
"reload:envision": "ssh envision pm2 restart root/code-center",
|
||||
"reload:kevisual": "ssh kevisual pm2 restart root/code-center",
|
||||
"pub:me": "npm run build && npm run deploy && npm run reload",
|
||||
"pub:envision": "npm run build && npm run deploy:envision && npm run reload:envision",
|
||||
"pub:kevisual": "npm run build && npm run deploy:kevisual && npm run reload:kevisual",
|
||||
"start": "pm2 start dist/app.js --name code-center",
|
||||
"client:start": "pm2 start apps/code-center/dist/app.js --name code-center",
|
||||
"ssl": "ssh -L 5432:localhost:5432 light",
|
||||
|
||||
@@ -5,14 +5,9 @@ import { logger } from './logger.ts';
|
||||
export const error = (msg: string, code = 500) => {
|
||||
return JSON.stringify({ code, message: msg });
|
||||
};
|
||||
export const checkAuth = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
export const getTokenFromRequest = (req: http.IncomingMessage) => {
|
||||
let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || '';
|
||||
const url = new URL(req.url || '', 'http://localhost');
|
||||
const resNoPermission = () => {
|
||||
res.statusCode = 401;
|
||||
res.end(error('Invalid authorization'));
|
||||
return { tokenUser: null, token: null };
|
||||
};
|
||||
if (!token) {
|
||||
token = url.searchParams.get('token') || '';
|
||||
}
|
||||
@@ -20,12 +15,21 @@ export const checkAuth = async (req: http.IncomingMessage, res: http.ServerRespo
|
||||
const parsedCookies = cookie.parse(req.headers.cookie || '');
|
||||
token = parsedCookies.token || '';
|
||||
}
|
||||
if (!token) {
|
||||
return resNoPermission();
|
||||
}
|
||||
if (token) {
|
||||
token = token.replace('Bearer ', '');
|
||||
}
|
||||
return token;
|
||||
}
|
||||
export const checkAuth = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
const token = getTokenFromRequest(req);
|
||||
const resNoPermission = () => {
|
||||
res.statusCode = 401;
|
||||
res.end(error('Invalid authorization'));
|
||||
return { tokenUser: null, token: null };
|
||||
};
|
||||
if (!token) {
|
||||
return resNoPermission();
|
||||
}
|
||||
let tokenUser;
|
||||
try {
|
||||
tokenUser = await User.verifyToken(token);
|
||||
@@ -54,19 +58,7 @@ export const getLoginUserByToken = async (token: string) => {
|
||||
}
|
||||
}
|
||||
export const getLoginUser = async (req: http.IncomingMessage) => {
|
||||
let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || '';
|
||||
const url = new URL(req.url || '', 'http://localhost');
|
||||
if (!token) {
|
||||
token = url.searchParams.get('token') || '';
|
||||
}
|
||||
if (!token) {
|
||||
const parsedCookies = cookie.parse(req.headers.cookie || '');
|
||||
token = parsedCookies.token || '';
|
||||
}
|
||||
|
||||
if (token) {
|
||||
token = token.replace('Bearer ', '');
|
||||
}
|
||||
let token = getTokenFromRequest(req);
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user