-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-238. Add conditional validation for auth route
- Loading branch information
1 parent
2843250
commit 431b95f
Showing
6 changed files
with
21 additions
and
35 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import {AuthLogin} from '../use-cases/auth' | ||
import {AuthLoginToken} from '../use-cases/auth' | ||
|
||
export default ({makeRunner}) => { | ||
return { | ||
login: makeRunner(AuthLogin, { | ||
toParams: (req) => ({...req.body}), | ||
}), | ||
loginWithToken: makeRunner(AuthLoginToken, { | ||
toParams: (req) => ({...req.body}), | ||
}), | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,29 @@ import {apiToken} from '../utils' | |
|
||
export class AuthLogin extends UseCase { | ||
static rules = { | ||
email: ['required', 'email'], | ||
password: 'required', | ||
credentials: [{ | ||
or: [{ | ||
nested_object: { | ||
password: ['required'], | ||
email: ['required', 'email'] | ||
} | ||
}, { | ||
nested_object: { | ||
token: ['required'] | ||
} | ||
}] | ||
}, 'required'] | ||
} | ||
|
||
|
||
async run(params) { | ||
// eslint-disable-next-line no-unused-vars | ||
const {credentials: { token, password, email }} = params | ||
|
||
if (token) { | ||
apiToken.verify(token) | ||
} | ||
|
||
return { | ||
token: apiToken.sign(params), | ||
email: '[email protected]', | ||
|
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './AuthLogin' | ||
export * from './AuthLoginToken' |
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