Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const validateLogin = auth => {
- const checkUsername = auth => auth.username
- ? Right.of(auth)
- : Left.of('No Username')
- const checkPassword = auth => auth.password
- ? Right.of(auth)
- : Left.of('Password Empty')
- const checkMatch = auth => (auth.username === 'jihad' && auth.password === 'jihad123')
- ? Right.of(auth.username)
- : Left.of('Username && password mismatch')
- const formatError = e => `error: ${e}`
- const successfulMsg = username => `Welcome back, ${username}!`
- return Either.of(auth)
- .bind(checkUsername)
- .bind(checkPassword)
- .bind(checkMatch)
- .cata(formatError, successfulMsg)
- }
- console.log(validateLogin(auth)())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement