test
This commit is contained in:
@@ -20,27 +20,27 @@ export const getTokenFromRequest = (req: http.IncomingMessage) => {
|
||||
}
|
||||
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);
|
||||
} catch (e) {
|
||||
console.log('checkAuth error', e);
|
||||
res.statusCode = 401;
|
||||
res.end(error('Invalid token'));
|
||||
return { tokenUser: null, token: null };
|
||||
}
|
||||
return { tokenUser, 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);
|
||||
// } catch (e) {
|
||||
// console.log('checkAuth error', e);
|
||||
// res.statusCode = 401;
|
||||
// res.end(error('Invalid token'));
|
||||
// return { tokenUser: null, token: null };
|
||||
// }
|
||||
// return { tokenUser, token };
|
||||
// };
|
||||
|
||||
export const getLoginUserByToken = async (token: string) => {
|
||||
if (token) {
|
||||
|
||||
Reference in New Issue
Block a user