-
-
Save navanathjadhav/b0070a6bc794ddbdfe943af588a0eda2 to your computer and use it in GitHub Desktop.
Ugly Code Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// My former colleague Akash has written this function, I'm scared to remove it. Hence I have commented it if I need it in future | |
// function oldLogin(credentials) { | |
// if (!credentials.userName) { | |
// throw new Error(`No username`) | |
// } | |
// if (!credentials.password) { | |
// throw new Error(`No password`) | |
// } | |
// } | |
// Lets do the login | |
function login(userName, password) { | |
// Some random comment | |
if (!userName) { | |
throw new Error(`No username`) | |
// some random ugly comment | |
} | |
if (!password) { | |
// Don't know where I will catch this | |
throw new Error(`No password`) | |
} | |
// Ohh god | |
const user = UserSchema.find({ email: userName, password: password }) | |
if (!user) { | |
// Incorrect userrname or password | |
throw new Error(`Invalid credentials`) | |
} | |
// OMG this conditions are scaring | |
if (user.status == 'Active') { | |
return { message: 'Login successful', user: user } | |
} else if (user.status == 'Inactive') { | |
return { message: 'User is inactive', user: undefined } | |
} else if (user.status == 'Invited') { | |
return { message: 'User is not activated yet', user: undefined } | |
} else if (user.status == 'Blocked') { | |
return { message: 'User is blocked', user: undefined } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment