Amal Jose commited on
Commit ·
5a1ffec
1
Parent(s): fc50dd8
fix: jwt algorithm
Browse filesFiles changed (8)
78 unmodified lines79808182838485154 unmodified lines24024124224324424524678 unmodified linesreturn;}try {const decoded = jwt.verify(refreshToken, ENVS.REFRESH_TOKEN_SECRET as string) as RefresheTokenType;console.log("Trying to decode refesh", decoded);const user = await userService.getUser(decoded.id);154 unmodified linesres.status(STATUS_CODES.BAD_REQUEST).json({ message: "Cant send otp, insufficient data" });return;}const decoded = jwt.verify(otpCookie, ENVS.VERIFICATION_TOKEN_SECRET as string) as { id: string };const { id } = decoded;const result = await userService.resentOtp(id || "---");78 unmodified lines7980818283848586878889154 unmodified lines24424524624724824925025125225325478 unmodified linesreturn;}try {const decoded = jwt.verify(refreshToken, ENVS.REFRESH_TOKEN_SECRET as string,{algorithms: ["HS256"],}) as RefresheTokenType;console.log("Trying to decode refesh", decoded);const user = await userService.getUser(decoded.id);154 unmodified linesres.status(STATUS_CODES.BAD_REQUEST).json({ message: "Cant send otp, insufficient data" });return;}const decoded = jwt.verify(otpCookie, ENVS.VERIFICATION_TOKEN_SECRET as string,{algorithms: ["HS256"],}) as { id: string };const { id } = decoded;const result = await userService.resentOtp(id || "---");
1234567import z from "zod";export const SignUpSchema = z.object({name: z.string().min(3).max(30),email: z.email(),password: z.string().min(8).max(64).regex(/\d/, "Password must contain at least one number"),});1234567import z from "zod";export const SignUpSchema = z.object({name: z.string().min(3).max(30).regex(/^[^\p{Emoji_Presentation}\p{Extended_Pictographic}]*$/u, "Name cannot contain emojis"),email: z.email(),password: z.string().min(8).max(64).regex(/\d/, "Password must contain at least one number"),});
18 unmodified lines1920212223242518 unmodified linesghRepoId: z.number().optional(),provider: z.enum(ProjectProvider),isPrivate: z.boolean(),name: z.string().min(3, "Name should not exceed 3 charecters").max(50, "Name max 50 characters"),repoURL: z.string().regex(18 unmodified lines1920212223242518 unmodified linesghRepoId: z.number().optional(),provider: z.enum(ProjectProvider),isPrivate: z.boolean(),name: z.string().min(3, "Name should not exceed 3 charecters").max(50, "Name max 50 characters").regex(/^[^\p{Emoji_Presentation}\p{Extended_Pictographic}]*$/u, "Name cannot contain emojis"),repoURL: z.string().regex(
13 unmodified lines1415161718192013 unmodified linesreturn res.status(STATUS_CODES.UNAUTHORIZED).json({ message: USER_ERRORS.NO_TOKEN });}const decoded = jwt.verify(serviceToken, ENVS.SERVICE_JWT_SECRET) as { pId: string; dId: string };// console.log(decoded);const server_token = ENVS.CONTAINER_API_TOKEN;if (containerToken !== server_token) {13 unmodified lines14151617181920212213 unmodified linesreturn res.status(STATUS_CODES.UNAUTHORIZED).json({ message: USER_ERRORS.NO_TOKEN });}const decoded = jwt.verify(serviceToken, ENVS.SERVICE_JWT_SECRET, {algorithms: ["HS256"],}) as { pId: string; dId: string };// console.log(decoded);const server_token = ENVS.CONTAINER_API_TOKEN;if (containerToken !== server_token) {
12 unmodified lines1314151617181910 unmodified lines3031323334353612 unmodified linesdeclare global {namespace Express {interface User extends DecodedUser {}interface Request {validatedQuery?: any;validatedBody?: any;10 unmodified linesreturn;}try {const decoded = jwt.verify(token, ENVS.ACCESS_TOKEN_SECRET as string) as DecodedUser;req.user = decoded;if (!req.user) {res.status(STATUS_CODES.UNAUTHORIZED).json({ message: USER_ERRORS.LOGIN_REQUIRED });12 unmodified lines1314151617181910 unmodified lines30313233343536373812 unmodified linesdeclare global {namespace Express {interface User extends DecodedUser { }interface Request {validatedQuery?: any;validatedBody?: any;10 unmodified linesreturn;}try {const decoded = jwt.verify(token, ENVS.ACCESS_TOKEN_SECRET as string, {algorithms: ["HS256"],}) as DecodedUser;req.user = decoded;if (!req.user) {res.status(STATUS_CODES.UNAUTHORIZED).json({ message: USER_ERRORS.LOGIN_REQUIRED });
14 unmodified lines1516171819202114 unmodified linesif (!stateValue) {throw new WebhookError(WEBHOOK_ERRORS.INCOMPLE_DATA, STATUS_CODES.BAD_REQUEST);}const decoded = jwt.verify(stateValue, ENVS.GITHUB_CLIENT_ID + ENVS.GITHUB_WEBHOOK_SECRET);req.body = decoded;next();} catch (error: any) {14 unmodified lines151617181920212223242514 unmodified linesif (!stateValue) {throw new WebhookError(WEBHOOK_ERRORS.INCOMPLE_DATA, STATUS_CODES.BAD_REQUEST);}const decoded = jwt.verify(stateValue, ENVS.GITHUB_CLIENT_ID + ENVS.GITHUB_WEBHOOK_SECRET,{algorithms: ["HS256"],});req.body = decoded;next();} catch (error: any) {
93 unmodified lines94959697989910093 unmodified linesconst otp = await this.otpService.createNew(newUser._id, OtpPurposes.SIGNUP);const sendResult = await this.otpService.sendOtp(newUser.email, newUser.name, otp.otp);if (!sendResult.ok) {throw new AppError("OTP Sent Error", 500);}const resultData = await sendResult.json();93 unmodified lines94959697989910093 unmodified linesconst otp = await this.otpService.createNew(newUser._id, OtpPurposes.SIGNUP);const sendResult = await this.otpService.sendOtp(newUser.email, newUser.name, otp.otp);if (!sendResult.ok) {throw new AppError("Error on senting OTP; Please try other methods", 500);}const resultData = await sendResult.json();
24 unmodified lines2526272829303113 unmodified lines454647484950518 unmodified lines6061626364656624 unmodified linesplan: user?.plan,},ENVS.ACCESS_TOKEN_SECRET as string,{ expiresIn: ENVS.NODE_ENV === "production" ? "15m" : "2h" },);return token;};13 unmodified linesoIAT: refreshTokenOptions.originalIssuedAt,},ENVS.REFRESH_TOKEN_SECRET as string,{ expiresIn: "1d" },);return token;};8 unmodified linespurpose: "OTP_resend",},ENVS.VERIFICATION_TOKEN_SECRET as string,{ expiresIn: "20m" },);return token;};24 unmodified lines2526272829303113 unmodified lines454647484950518 unmodified lines6061626364656624 unmodified linesplan: user?.plan,},ENVS.ACCESS_TOKEN_SECRET as string,{ algorithm: "HS256", expiresIn: ENVS.NODE_ENV === "production" ? "15m" : "2h" },);return token;};13 unmodified linesoIAT: refreshTokenOptions.originalIssuedAt,},ENVS.REFRESH_TOKEN_SECRET as string,{ algorithm: "HS256", expiresIn: "1d" },);return token;};8 unmodified linespurpose: "OTP_resend",},ENVS.VERIFICATION_TOKEN_SECRET as string,{ algorithm: "HS256", expiresIn: "20m" },);return token;};
src/controllers/authController.ts+10-2
src/dtos/auth.dto.ts+1-1
src/dtos/project.dto.ts+1-1
src/middlewares/authContainerMiddleware.ts+3-1
src/middlewares/authMiddleware.ts+4-2
src/middlewares/github.middlewares.ts+5-1
src/services/user.service.ts+1-1
src/utils/generateToken.ts+3-3