update webauthn flow

This commit is contained in:
2025-02-27 16:34:20 +05:30
parent 0b9f941cb3
commit 63bcc4bafd
5 changed files with 45 additions and 45 deletions

View File

@@ -1,16 +1,31 @@
import mongoose from "mongoose";
import { generateId } from "../utils/id";
import { generateId, generateToken } from "../utils/id";
import { CreateUserInput, UpdateUserInput, userModel } from "./user.schema";
import { sendMail } from "../utils/mail";
export async function createUser(input: CreateUserInput, tenantId: string) {
const token = await generateToken();
const user = await userModel.create({
tenantId: tenantId,
pid: generateId(),
name: input.firstName + " " + input.lastName,
createdAt: new Date(),
token: {
value: token,
expiry: new Date(Date.now() + 3600 * 6 * 1000),
},
...input,
});
const sent = await sendMail(
input.email,
"You have been invited to Quicker Permtis.",
`Click <a href="${
process.env.SERVER_DOMAIN + "/auth/webauthn/regiester?token=" + token
}">here</a> to register.`
);
return user;
}
@@ -24,6 +39,10 @@ export async function getUser(userId: string) {
});
}
export async function getUserByToken(token: string) {
return await userModel.findOne({ "token.value": token });
}
export async function getUserByEmail(email: string) {
return await userModel.findOne({ email: email });
}