Skip to content

Commit

Permalink
[#21] Base and Auth adapter for sending request, only includes login …
Browse files Browse the repository at this point in the history
…functionality wip
  • Loading branch information
liamstevens111 committed Feb 16, 2023
1 parent 5f1297c commit 0bdc754
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
23 changes: 23 additions & 0 deletions src/adapters/authAdapter.ts
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;
13 changes: 13 additions & 0 deletions src/adapters/baseAdapter..ts
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;
2 changes: 2 additions & 0 deletions src/lib/requestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const defaultOptions: { responseType: ResponseType } = {
responseType: 'json',
};

export type RequestParamsType = AxiosRequestConfig;

/**
* The main API access function that comes preconfigured with useful defaults.
*
Expand Down

0 comments on commit 0bdc754

Please sign in to comment.