Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop sending verifcation email when host is empty #667

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions server/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const authenticate = (
if (user && isStrict && !user.verified) {
throw new CustomError(
"Your email address is not verified. " +
"Click on signup to get the verification link again.",
"Click on signup to get the verification link again.",
400
);
}
Expand Down Expand Up @@ -111,18 +111,37 @@ export const admin: Handler = async (req, res, next) => {
throw new CustomError("Unauthorized", 401);
};

export const signup: Handler = async (req, res) => {
export const signup: Handler = async (req, res, next) => {
const salt = await bcrypt.genSalt(12);
const password = await bcrypt.hash(req.body.password, salt);

const user = await query.user.add(
{ email: req.body.email, password },
req.user
);
if (!env.MAIL_HOST) {
const [user_verified] = await query.user.update(
{
verification_token: user.verification_token,
verification_expires: [">", new Date().toISOString()]
},
{
verified: true,
verification_token: null,
verification_expires: null
}
);

await mail.verification(user);

return res.status(201).send({ message: "Verification email has been sent." });
if (user_verified) {
const token = utils.signToken(user);
req.token = token;
}
return next();
}
else {
await mail.verification(user);
return res.status(201).send({ message: "User created" });
}
};

export const token: Handler = async (req, res) => {
Expand Down