Skip to content

Commit

Permalink
feat(login): add login functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmicunda committed May 31, 2019
1 parent 917a208 commit 624c99a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,20 @@ export const apiGatewayProxyResultMock = (
body: JSON.stringify(body || '{}'),
headers: headers || undefined,
});

export const login = async (
// tslint:disable:no-any
server: any,
email: string,
password: string
): Promise<{ accessToken: string; accountId: string; idToken: string }> => {
const base64Password = Buffer.from(`${email}:${password}`).toString('base64');
const { id_token, access_token } = (await server
.post('/auth/login')
.set('Authorization', `Basic ${base64Password}`)).body;
const accountId = JSON.parse(
Buffer.from(id_token.split('.')[1], 'base64').toString('ascii')
).aud;

return { accountId, accessToken: access_token, idToken: id_token };
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"lint": "tslint -t stylish --project tsconfig.json",
"lint:fix": "npm run lint -- --fix",
"check": "npm run lint && npm run prettier:check",
"prettier:base-files": "prettier --single-quote --trailing-comma es5 ./**/*.ts",
"prettier:base-files": "prettier --single-quote --trailing-comma es5 './**/*.ts'",
"prettier:check": "npm run prettier:base-files -- -l",
"prettier:fix": "npm run prettier:base-files -- --write",
"semantic-release": "semantic-release"
Expand All @@ -41,7 +41,7 @@
"hooks": {
"pre-commit": "lint-staged",
"prepare-commit-msg": "exec < /dev/tty && git cz --hook",
"post-merge": "npm install"
"post-merge": "npm ci"
}
},
"lint-staged": {
Expand Down

0 comments on commit 624c99a

Please sign in to comment.