updated login flow
This commit is contained in:
@@ -28,6 +28,7 @@ const userSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
passwordHash: String,
|
||||
passKeys: [new mongoose.Schema({}, { _id: false, strict: false })],
|
||||
challenge: new mongoose.Schema(
|
||||
{
|
||||
@@ -68,6 +69,7 @@ const userCore = {
|
||||
avatar: z.string().optional(),
|
||||
role: z.enum(roles),
|
||||
orgId: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
};
|
||||
|
||||
const createUserInput = z
|
||||
|
||||
@@ -4,6 +4,7 @@ import { CreateUserInput, UpdateUserInput, userModel } from "./user.schema";
|
||||
import { sendMail } from "../utils/mail";
|
||||
import { AuthenticatedUser } from "../auth";
|
||||
import { createUserConfig } from "../userConfig/userConfig.service";
|
||||
import { hash } from "argon2";
|
||||
|
||||
export const ErrUserNotFound = new Error("user not found");
|
||||
export const ErrOpNotValid = new Error("operation is not valid");
|
||||
@@ -26,7 +27,8 @@ export async function createUser(
|
||||
throw ErrMissingOrdId;
|
||||
}
|
||||
|
||||
const token = await generateToken();
|
||||
let hashedPassword = "";
|
||||
if (input.password) hashedPassword = await hash(input.password);
|
||||
|
||||
const newUser = await userModel.create({
|
||||
tenantId: user.tenantId,
|
||||
@@ -34,16 +36,25 @@ export async function createUser(
|
||||
name: input.firstName + " " + input.lastName,
|
||||
createdAt: new Date(),
|
||||
createdBy: user.userId,
|
||||
token: {
|
||||
value: token,
|
||||
expiry: new Date(Date.now() + 3600 * 48 * 1000),
|
||||
},
|
||||
status: "invited",
|
||||
status: input.password ? "active" : "invited",
|
||||
passwordHash: hashedPassword,
|
||||
...input,
|
||||
});
|
||||
|
||||
await createUserConfig(newUser.id, newUser.tenantId);
|
||||
|
||||
if (input.password)
|
||||
return newUser.populate({ path: "orgId", select: "pid name avatar" });
|
||||
|
||||
const token = await generateToken();
|
||||
|
||||
newUser.token = {
|
||||
value: token,
|
||||
expiry: new Date(Date.now() + 3600 * 48 * 1000),
|
||||
};
|
||||
|
||||
await newUser.save();
|
||||
|
||||
const sent = await sendMail(
|
||||
input.email,
|
||||
"You have been invited to Quicker Permtis.",
|
||||
|
||||
Reference in New Issue
Block a user