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

Fix Mandatory email setup #706

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions client/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const LoginPage = () => {
const { isAuthenticated } = useStoreState((s) => s.auth);
const login = useStoreActions((s) => s.auth.login);
const [error, setError] = useState("");
const [verifying, setVerifying] = useState(false);
const [message, setMessage] = useState("");
const [loading, setLoading] = useState({ login: false, signup: false });
const [formState, { email, password, label }] = useFormState<{
email: string;
Expand Down Expand Up @@ -79,8 +79,8 @@ const LoginPage = () => {
if (type === "signup" && !DISALLOW_REGISTRATION) {
setLoading((s) => ({ ...s, signup: true }));
try {
await axios.post(APIv2.AuthSignup, { email, password });
setVerifying(true);
const res = await axios.post(APIv2.AuthSignup, { email, password });
setMessage(res.data.message);
} catch (error) {
setError(error.response.data.error);
}
Expand All @@ -97,10 +97,9 @@ const LoginPage = () => {
return (
<AppWrapper>
<ColCenterV maxWidth="100%" px={3} flex="0 0 auto" mt={4}>
{verifying ? (
{message ? (
<H2 textAlign="center" light>
A verification email has been sent to{" "}
<Email>{formState.values.email}</Email>.
{message}
</H2>
) : (
<LoginForm id="login-form" onSubmit={onSubmit("login")}>
Expand Down
9 changes: 8 additions & 1 deletion server/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,16 @@ export const signup: Handler = async (req, res) => {
req.user
);

if (!process.env.MAIL_HOST) {
return res
.status(201)
.send({ message: "Your account has been created successfully." });
}
await mail.verification(user);

return res.status(201).send({ message: "Verification email has been sent." });
return res
.status(201)
.send({ message: `Verification email has been sent to ${user.email}.` });
};

export const token: Handler = async (req, res) => {
Expand Down
3 changes: 2 additions & 1 deletion server/queries/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const add = async (params: Add, user?: User) => {
email: params.email,
password: params.password,
verification_token: uuid(),
verification_expires: addMinutes(new Date(), 60).toISOString()
verification_expires: addMinutes(new Date(), 60).toISOString(),
verified: process.env.MAIL_HOST ? false : true
};

if (user) {
Expand Down