added disable email verification option
This commit is contained in:
@@ -18,6 +18,7 @@ export default {
|
||||
sendgridKey: process.env.SENDGRID_KEY,
|
||||
sendgridEmail: process.env.SENDGRID_EMAIL,
|
||||
remoteURL: process.env.REMOTE_URL,
|
||||
disableEmailVerification: process.env.DISABLE_EMAIL_VERIFICATION
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@@ -40,4 +41,5 @@ module.exports = {
|
||||
sendgridKey: process.env.SENDGRID_KEY,
|
||||
sendgridEmail: process.env.SENDGRID_EMAIL,
|
||||
remoteURL: process.env.REMOTE_URL,
|
||||
disableEmailVerification: process.env.DISABLE_EMAIL_VERIFICATION
|
||||
}
|
||||
@@ -40,7 +40,7 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => {
|
||||
//console.log(user.email);
|
||||
|
||||
if (!user) throw new Error("No User");
|
||||
if (!user.emailVerified) throw new Error("Email Not Verified")
|
||||
if (!user.emailVerified && !env.disableEmailVerification) throw new Error("Email Not Verified")
|
||||
|
||||
req.user = user;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const authFullUser = async(req: RequestType, res: Response, next: NextFunction)
|
||||
const user = decoded.user;
|
||||
|
||||
if (!user) throw new Error("No User");
|
||||
if (!user.emailVerified) throw new Error("Email Not Verified")
|
||||
if (!user.emailVerified && !env.disableEmailVerification) throw new Error("Email Not Verified")
|
||||
|
||||
const fullUser = await User.findById(user._id);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => {
|
||||
|
||||
if (!user) throw new Error("No User");
|
||||
|
||||
if (!user.emailVerified) {
|
||||
if (!user.emailVerified && !env.disableEmailVerification) {
|
||||
const ipAddress = req.clientIp;
|
||||
user = await userUpdateCheck(res, user._id, ipAddress);
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ userSchema.methods.generateAuthToken = async function(ipAddress: string | undefi
|
||||
const date = new Date();
|
||||
const time = date.getTime();
|
||||
|
||||
const userObj = {_id: user._id, emailVerified: user.emailVerified, email: user.email, s3Enabled: user.s3Enabled, googleDriveEnabled: user.googleDriveEnabled}
|
||||
const userObj = {_id: user._id, emailVerified: user.emailVerified || env.disableEmailVerification, email: user.email, s3Enabled: user.s3Enabled, googleDriveEnabled: user.googleDriveEnabled}
|
||||
|
||||
let accessToken = jwt.sign({user: userObj, iv}, env.passwordAccess!, {expiresIn: maxAgeAccess.toString()});
|
||||
let refreshToken = jwt.sign({_id:user._id.toString(), iv, time}, env.passwordRefresh!, {expiresIn: maxAgeRefresh.toString()});
|
||||
|
||||
@@ -106,7 +106,7 @@ class UserService {
|
||||
|
||||
create = async(userData: any, ipAddress: string | undefined) => {
|
||||
|
||||
const user = new User({email: userData.email, password: userData.password});
|
||||
const user = new User({email: userData.email, password: userData.password, emailVerified: env.disableEmailVerification});
|
||||
await user.save();
|
||||
|
||||
if (!user) throw new NotFoundError("User Not Found");
|
||||
@@ -116,7 +116,7 @@ class UserService {
|
||||
const {accessToken, refreshToken} = await user.generateAuthToken(ipAddress);
|
||||
const emailToken = await user.generateEmailVerifyToken();
|
||||
|
||||
await sendEmailVerification(user, emailToken);
|
||||
if (!env.disableEmailVerification) await sendEmailVerification(user, emailToken);
|
||||
|
||||
if (!accessToken || !refreshToken) throw new InternalServerError("Could Not Create New User Error");
|
||||
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ export const startCreateAccount = (email, password) => {
|
||||
const id = response.data.user._id;
|
||||
const emailVerified = response.data.user.emailVerified;
|
||||
|
||||
window.localStorage.setItem("token", token);
|
||||
// window.localStorage.setItem("token", token);
|
||||
|
||||
if (emailVerified) {
|
||||
dispatch(setLoginFailed(false))
|
||||
|
||||
Reference in New Issue
Block a user