edit:module:user:*update | add refresh jwt token after user doing chances
This commit is contained in:
@ -7,6 +7,10 @@ import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { editUserService } from "../services/editUser.service";
|
||||
import { getCookie } from "../../../helpers/http/userHeader/cookies/getCookies";
|
||||
import { getUserHeaderInformation } from "../../../helpers/http/userHeader/getUserHeaderInformation";
|
||||
import { setCookie } from "../../../helpers/http/userHeader/cookies/setCookies";
|
||||
import { COOKIE_KEYS } from "../../../constants/cookie.keys";
|
||||
import { jwtEncode } from "../../../helpers/http/jwt/encode";
|
||||
|
||||
export const editUserController = async (
|
||||
ctx: Context & {
|
||||
@ -19,8 +23,18 @@ export const editUserController = async (
|
||||
if (!auth_token)
|
||||
return returnErrorResponse(ctx.set, 401, "User Unauthenticated");
|
||||
|
||||
const editUser = await editUserService(auth_token, ctx.body);
|
||||
return editUser;
|
||||
const userHeaderInfo = getUserHeaderInformation(ctx);
|
||||
|
||||
const newUserData = await editUserService(
|
||||
auth_token,
|
||||
userHeaderInfo,
|
||||
ctx.body
|
||||
);
|
||||
|
||||
const newJwtToken = await jwtEncode(newUserData);
|
||||
setCookie(ctx.set, COOKIE_KEYS.AUTH, newJwtToken);
|
||||
|
||||
return returnWriteResponse(ctx.set, 201, "User data updated", newJwtToken);
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user