RBAC, jwt implemented in Projects,home and collections routing

This commit is contained in:
2025-09-01 16:52:30 +05:30
parent b8950dc42d
commit 322db1911b
17 changed files with 503 additions and 175 deletions

View File

@@ -1,11 +1,10 @@
import redis from "../connection/redis";
import tokenModel from "../model/tokenModel";
import nodemailer from "nodemailer";
import userModel from "../model/userModel";
import { hashGenerate, hashValidator } from "../utils/hashing";
import { tokenGenerator, tokenRefreshGenerator } from "../utils/token";
import { text } from "body-parser";
import userDataModel from "../model/userDataModel";
interface Iresponse {
status: string;
@@ -45,7 +44,7 @@ export const signupService = async (data: Isignup): Promise<Iresponse> => {
let role;
const passwordHashed = await hashGenerate(password);
const userCount = await userModel(organization).countDocuments({});
role = userCount === 0 ? "Admin" : "User";
role = userCount === 0 ? "Admin" : "Viewer";
const newUser = await userModel(organization).create({
userName,
email: mailCaseChange,
@@ -81,6 +80,15 @@ export const signinService = async (data: Isignin): Promise<Iresponse> => {
);
if (!comparePassword)
return { status: "Password is invalid...Check the credentials" };
const userDataExistence = await userDataModel(organization).findOne({
userId: mailExistance._id,
isArchive: false,
});
if (!userDataExistence) {
const userDatacreation = await userDataModel(organization).create({
userId: mailExistance._id,
});
}
const tokenValidation = tokenGenerator(
mailExistance.email,
mailExistance.role,
@@ -145,13 +153,10 @@ export const forgetPassword = async ({
email,
}: IforGotPassword): Promise<{ status: string }> => {
try {
console.log("hi forgetpassword");
const mailCaseChange = email.toLocaleLowerCase();
const organization = email.split("@")[1].split(".")[0];
const Existing_User = await existingUserData(mailCaseChange, organization);
console.log("Existing_User: ", Existing_User);
if (Existing_User) {
console.log("if");
// if (Existing_User.lastPasswordReset) {
// console.log("if2");
// const lastPasswordReset = Existing_User.lastPasswordReset;
@@ -163,8 +168,6 @@ export const forgetPassword = async ({
// status: "You can only reset your password once every 24 hours.",
// };
// }
console.log("process.env.EMAIL_USER: ", process.env.EMAIL_USER);
console.log("process.env.EMAIL_PASS: ", process.env.EMAIL_PASS);
const transport = nodemailer.createTransport({
service: "gmail",
secure: true,