token refresh
This commit is contained in:
parent
55caf69bf0
commit
03e0f90279
4 changed files with 40 additions and 9 deletions
|
@ -3,7 +3,7 @@ import { JWTHelper } from "../helpers/jwtHelper";
|
|||
import { JWTData, JWTToken } from "../type/jwtTypes";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import RefreshCommandHandler from "../command/refreshCommandHandler";
|
||||
import { CreateRefreshCommand } from "../command/refreshCommand";
|
||||
import { CreateRefreshCommand, DeleteRefreshCommand } from "../command/refreshCommand";
|
||||
import UserService from "../service/userService";
|
||||
import speakeasy from "speakeasy";
|
||||
import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException";
|
||||
|
@ -80,8 +80,8 @@ export async function logout(req: Request, res: Response): Promise<any> {}
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function refresh(req: Request, res: Response): Promise<any> {
|
||||
let token = req.body.token;
|
||||
let refresh = req.body.refresh;
|
||||
let token = req.body.accessToken;
|
||||
let refresh = req.body.refreshToken;
|
||||
|
||||
const tokenUser = await JWTHelper.decode(token);
|
||||
if (typeof tokenUser == "string" || !tokenUser) {
|
||||
|
@ -121,7 +121,11 @@ export async function refresh(req: Request, res: Response): Promise<any> {
|
|||
};
|
||||
refreshToken = await RefreshCommandHandler.create(refreshCommand);
|
||||
|
||||
await RefreshCommandHandler.deleteByToken(refresh);
|
||||
let removeToken: DeleteRefreshCommand = {
|
||||
userId: id,
|
||||
token: refresh,
|
||||
};
|
||||
await RefreshCommandHandler.deleteByToken(removeToken);
|
||||
|
||||
res.json({
|
||||
accessToken,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue