Skip to content

Commit f4405d6

Browse files
feat: By-pass email verification on development environment (#408)
Co-authored-by: Sanchit Bajaj <55249639+Sanchitbajaj02@users.noreply.github.com>
1 parent caa525b commit f4405d6

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/backend/auth.api.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ const register = async (userData: {
4747
throw new Error("User data can't be saved properly");
4848
}
4949

50-
const createVerify = await account.createVerification(
51-
`${process.env.NEXT_PUBLIC_BASE_URL}/verify`,
52-
);
53-
54-
if (!createVerify) {
55-
throw new Error("Error sending verification email");
50+
// send verification email in production mode
51+
if (process.env.NODE_ENV === "production") {
52+
const createVerify = await account.createVerification(
53+
`${process.env.NEXT_PUBLIC_BASE_URL}/verify`,
54+
);
55+
56+
if (!createVerify) {
57+
throw new Error("Error sending verification email");
58+
}
5659
}
5760

5861
return dbData;
@@ -245,7 +248,10 @@ const saveDataToDatabase = async (session: any) => {
245248
const resp = await db.createDocument(palettegramDB, usersCollection, ID.unique(), {
246249
email: session.email,
247250
fullName: session.name,
248-
isVerified: session.emailVerification,
251+
isVerified:
252+
process.env.NODE_ENV === "development"
253+
? true // user verified by default in dev environment
254+
: session.emailVerification,
249255
accountId: session.$id,
250256
username: session?.prefs?.username,
251257
avatarURL: avatar,

src/components/pages/auth/register/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ export default function RegisterComponent() {
8989
dispatch(saveUserToStore(payload));
9090

9191
setIsLoading(false);
92-
toastify("Register Successful. Please check your email to verify", "success");
93-
router.push("/verify");
92+
if (process.env.NODE_ENV === "production") {
93+
toastify("Register Successful. Please check your email to verify", "success");
94+
router.push("/verify");
95+
} else {
96+
toastify("Register Successful", "success");
97+
router.push("/feed");
98+
}
9499
} catch (error: any) {
95100
setIsLoading(false);
96101

0 commit comments

Comments
 (0)