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

feat: By-pass email verification on development environment #408

Merged
merged 3 commits into from
Jul 29, 2024
Merged
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
20 changes: 13 additions & 7 deletions src/backend/auth.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ const register = async (userData: {
throw new Error("User data can't be saved properly");
}

const createVerify = await account.createVerification(
`${process.env.NEXT_PUBLIC_BASE_URL}/verify`,
);

if (!createVerify) {
throw new Error("Error sending verification email");
// send verification email in production mode
if (process.env.NODE_ENV === "production") {
Sanchitbajaj02 marked this conversation as resolved.
Show resolved Hide resolved
const createVerify = await account.createVerification(
`${process.env.NEXT_PUBLIC_BASE_URL}/verify`,
);

if (!createVerify) {
throw new Error("Error sending verification email");
}
}

return dbData;
Expand Down Expand Up @@ -245,7 +248,10 @@ const saveDataToDatabase = async (session: any) => {
const resp = await db.createDocument(palettegramDB, usersCollection, ID.unique(), {
email: session.email,
fullName: session.name,
isVerified: session.emailVerification,
isVerified:
process.env.NODE_ENV === "development"
? true // user verified by default in dev environment
: session.emailVerification,
accountId: session.$id,
username: session?.prefs?.username,
avatarURL: avatar,
Expand Down
9 changes: 7 additions & 2 deletions src/components/pages/auth/register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ export default function RegisterComponent() {
dispatch(saveUserToStore(payload));

setIsLoading(false);
toastify("Register Successful. Please check your email to verify", "success");
router.push("/verify");
if (process.env.NODE_ENV === "production") {
toastify("Register Successful. Please check your email to verify", "success");
router.push("/verify");
} else {
toastify("Register Successful", "success");
router.push("/feed");
}
} catch (error: any) {
setIsLoading(false);

Expand Down
Loading