Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ugly Code Example
// 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