generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#21] Base and Auth adapter for sending request, only includes login …
…functionality wip
- Loading branch information
1 parent
5f1297c
commit 0bdc754
Showing
4 changed files
with
39 additions
and
0 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import BaseAdapter from './baseAdapter.'; | ||
|
||
type LoginAuthType = { | ||
email: string; | ||
password: string; | ||
}; | ||
|
||
class AuthAdapter extends BaseAdapter { | ||
static login(params: LoginAuthType) { | ||
/* eslint-disable camelcase */ | ||
const requestParams = { | ||
...params, | ||
grant_type: 'password', | ||
client_id: process.env.REACT_APP_API_CLIENT_ID, | ||
client_secret: process.env.REACT_APP_API_CLIENT_SECRET, | ||
}; | ||
/* eslint-enable camelcase */ | ||
|
||
return this.prototype.postRequest(`${process.env.REACT_APP_API_ENDPOINT}/oauth/token`, { data: requestParams }); | ||
} | ||
} | ||
|
||
export default AuthAdapter; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import requestManager, { RequestParamsType } from 'lib/requestManager'; | ||
|
||
class BaseAdapter { | ||
getRequest(endpoint: string, params: RequestParamsType) { | ||
return requestManager('GET', endpoint, params); | ||
} | ||
|
||
postRequest(endpoint: string, params: RequestParamsType) { | ||
return requestManager('POST', endpoint, params); | ||
} | ||
} | ||
|
||
export default BaseAdapter; |
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