improve email formatting and invite flow for new users

This commit is contained in:
Milo Schwartz 2024-12-31 18:25:11 -05:00
parent d244d6003b
commit d447de9e8a
No known key found for this signature in database
15 changed files with 107 additions and 89 deletions

View file

@ -84,6 +84,15 @@ export async function signup(
createHttpError(HttpCode.BAD_REQUEST, "Invite does not exist")
);
}
if (existingInvite.email !== email) {
return next(
createHttpError(
HttpCode.BAD_REQUEST,
"Invite is not for this user"
)
);
}
}
try {

View file

@ -137,7 +137,7 @@ authenticated.post(
verifyUserHasAction(ActionsEnum.inviteUser),
user.inviteUser
); // maybe make this /invite/create instead
authenticated.post("/invite/accept", user.acceptInvite);
unauthenticated.post("/invite/accept", user.acceptInvite); // this is supposed to be unauthenticated
authenticated.get(
"/resource/:resourceId/roles",

View file

@ -12,6 +12,7 @@ import { fromError } from "zod-validation-error";
import { isWithinExpirationDate } from "oslo";
import { verifyPassword } from "@server/auth/password";
import { checkValidInvite } from "@server/auth/checkValidInvite";
import { verifySession } from "@server/auth";
const acceptInviteBodySchema = z
.object({
@ -72,7 +73,9 @@ export async function acceptInvite(
);
}
if (req.user && req.user.email !== existingInvite.email) {
const { user, session } = await verifySession(req);
if (user && user.email !== existingInvite.email) {
return next(
createHttpError(
HttpCode.BAD_REQUEST,