Skip to content

Commit

Permalink
auth feature complete
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushjaiswal1610 committed Dec 31, 2023
1 parent ff8cbd7 commit f6b78ba
Show file tree
Hide file tree
Showing 41 changed files with 1,036 additions and 306 deletions.
2 changes: 1 addition & 1 deletion authservice/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const corsOptions = {
};

app.use(cors(corsOptions));
app.use(cookieParser())
app.use(cookieParser());
app.use(express.json({ limit: "10mb" }));
app.use(express.urlencoded({ limit: "10mb", extended: true }));

Expand Down
15 changes: 12 additions & 3 deletions authservice/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const signup = async (req: Request, res: Response) => {
.status(200)
.json(new ApiResponse(200, userData, "OTP sent successfully!"));
} catch (error: any) {
res.status(error.statusCode | 500).json({
res.status(error.statusCode).json({
success: false,
message: error.message,
});
Expand All @@ -82,14 +82,23 @@ const login = async (req: Request, res: Response) => {

res
.status(200)
.cookie("jwt", refreshToken, {
.cookie("jwt-refresh", refreshToken, {
httpOnly: true,
sameSite: false,
secure: true,
maxAge: 24 * 60 * 60 * 1000,
})
.json(
new ApiResponse(200, { accessToken }, "User logged in successfully!")
new ApiResponse(
200,
{
accessToken,
name: user.name,
email: user.email,
isVerified: user.isVerified,
},
"User logged in successfully!"
)
);
} catch (error: any) {
res.status(error.statusCode | 500).json({
Expand Down
1 change: 0 additions & 1 deletion authservice/src/controllers/otp.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const VerifyOtp = async (req: Request, res: Response) => {

if (!user) throw new ApiError(401, "User does not exists!");


if (user.last_otp === otp) {
const isUpdated = await myDataSource.getRepository(userEntity).save({
...user,
Expand Down
4 changes: 4 additions & 0 deletions authservice/src/middlewares/verifyJwt.middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// verify access token
// if expired , verify refresh token
// if refresh valid -> create new access token and save in cookies
// if refresh expired -> prompt user for login
5 changes: 3 additions & 2 deletions authservice/src/models/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export default new EntitySchema({
columns: {
id: {
type: "text",
unique: true,
primary: true,
},
name: {
type: "text",
unique: true,
unique: false,
nullable: false,
},
email: {
Expand All @@ -29,7 +30,7 @@ export default new EntitySchema({
last_otp: {
type: "text",
nullable: true,
}
},
},
});

Expand Down
11 changes: 6 additions & 5 deletions authservice/src/routes/auth.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ router.post(
signup
);

router.post("/login",
[
check("email").normalizeEmail().isEmail(),
check("password").isLength({ min: 6 }),
router.post(
"/login",
[
check("email").normalizeEmail().isEmail(),
check("password").isLength({ min: 6 }),
],
validateRequest,
login
)
);

export default router;
7 changes: 1 addition & 6 deletions authservice/src/utils/classes/ApiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ class ApiError extends Error {
success: boolean;
errors: any;

constructor(
statusCode: number,
message: string,
errors = [],
stack = ""
) {
constructor(statusCode: number, message: string, errors = [], stack = "") {
super(message);
this.statusCode = statusCode;
this.data = null;
Expand Down
5 changes: 2 additions & 3 deletions authservice/src/utils/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ export default async function sendMail(
user: process.env.SENDER_GMAIL_ADDRESS,
refreshToken: process.env.SENDER_GMAIL_REFRESH_TOKEN,
accessToken: process.env.SENDER_GMAIL_ACCESS_TOKEN,
expires: 1484314697598
}
expires: 1484314697598,
},
};


const info = await transporter.sendMail(mailOptions);
console.log("Message sent: %s", info.messageId);
Expand Down
9 changes: 3 additions & 6 deletions authservice/src/utils/email/template.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
export function newUserTemplate(
value: string | undefined
): string {
return `
export function newUserTemplate(value: string | undefined): string {
return `
Thanks for signing up to Virtual Connect. Just one last step before you can start using our services for free.
Here is your OTP for verification: ${value} \n \n
Regards
Piyush Jaiswal
(developer)`;
}


export function welcomeUserTemplate() {
return `
Verification success!
Expand All @@ -18,4 +15,4 @@ export function welcomeUserTemplate() {
Regards
Piyush Jaiswal
(developer)`;
}
}
8 changes: 4 additions & 4 deletions authservice/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// lib
export { default as generateOtp } from "./lib/generateOtp";
export { default as createUserId } from "./lib/createUserID";
export { hashPassword, verifyPassword } from './lib/encryptPassword'
export { hashPassword, verifyPassword } from "./lib/encryptPassword";
export { default as asyncHandler } from "./lib/asyncHandler";

// email
export { default as sendMail } from "./email";
export { newUserTemplate } from "./email/template";

// classes
export { default as ApiError } from './classes/ApiError'
export { default as ApiResponse } from './classes/ApiResponse'
export { default as ApiError } from "./classes/ApiError";
export { default as ApiResponse } from "./classes/ApiResponse";

// jwt
export { default as generateToken } from './jwt/generateToken'
export { default as generateToken } from "./jwt/generateToken";
2 changes: 1 addition & 1 deletion authservice/src/utils/jwt/generateToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function generateToken(

const token = jwt.sign(data, secret || "", {
expiresIn: expiryTime,
algorithm: "RS256",
// algorithm: "RS256",
});

return token;
Expand Down
2 changes: 1 addition & 1 deletion authservice/src/utils/lib/encryptPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function verifyPassword(
const res = bcrypt.compareSync(currPassword + secretKey, userPassword);
return res;
}
return false
return false;
}

export function hashPassword(password: string) {
Expand Down
12 changes: 6 additions & 6 deletions client/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"files": {
"main.css": "/static/css/main.b84184d6.css",
"main.js": "/static/js/main.29eca987.js",
"main.css": "/static/css/main.31d6379b.css",
"main.js": "/static/js/main.b1a21008.js",
"static/media/videocall.svg": "/static/media/videocall.ea35c31b6731f8d7e26130d62bb3d94f.svg",
"static/media/audiocall.svg": "/static/media/audiocall.4918d8229479afee0e117955fdf9ff88.svg",
"static/media/chatting.svg": "/static/media/chatting.0d578f5c69cf5629d45bdfddfdc7841c.svg",
"static/media/file.svg": "/static/media/file.d413d4fa944e3e36229b8d7cc7841482.svg",
"static/media/hero3.svg": "/static/media/hero3.9c530f208327e5c056ec8b5523d8af67.svg",
"static/media/logo.png": "/static/media/logo.6ab2f90d3594b680990f.png",
"index.html": "/index.html",
"main.b84184d6.css.map": "/static/css/main.b84184d6.css.map",
"main.29eca987.js.map": "/static/js/main.29eca987.js.map"
"main.31d6379b.css.map": "/static/css/main.31d6379b.css.map",
"main.b1a21008.js.map": "/static/js/main.b1a21008.js.map"
},
"entrypoints": [
"static/css/main.b84184d6.css",
"static/js/main.29eca987.js"
"static/css/main.31d6379b.css",
"static/js/main.b1a21008.js"
]
}
2 changes: 1 addition & 1 deletion client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href=""/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="Virtual Connect" content="Single platform for audio, video, and text based live communication"/><link href="/dist/output.css" rel="stylesheet"><title>Virtual Connect</title><script defer="defer" src="/static/js/main.29eca987.js"></script><link href="/static/css/main.b84184d6.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href=""/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="Virtual Connect" content="Single platform for audio, video, and text based live communication"/><link href="/dist/output.css" rel="stylesheet"><title>Virtual Connect</title><script defer="defer" src="/static/js/main.b1a21008.js"></script><link href="/static/css/main.31d6379b.css" rel="stylesheet"></head><body><div id="root"></div></body></html>

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/css/main.31d6379b.css.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/build/static/css/main.b84184d6.css.map

This file was deleted.

1 change: 0 additions & 1 deletion client/build/static/js/main.29eca987.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/js/main.b1a21008.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit f6b78ba

Please sign in to comment.