Skip to content

Commit

Permalink
Fixed some MFA related fields
Browse files Browse the repository at this point in the history
  • Loading branch information
danielholmes committed Feb 1, 2024
1 parent 5986c8f commit 2e699b1
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 58 deletions.
114 changes: 63 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@dhau/react-aws-cognito",
"version": "0.0.10",
"version": "0.0.11",
"type": "module",
"sideEffects": false,
"description": "Context and hooks to manage an AWS Cognito authenticated user in React.",
"main": "./dist/index.js",
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"exports": {
Expand Down Expand Up @@ -35,15 +35,15 @@
"author": "Daniel Holmes",
"license": "MIT",
"dependencies": {
"@dhau/lang-extras": "^0.0.4",
"@dhau/lang-extras": "^0.0.5",
"date-fns": "^3.3.1"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@types/lodash-es": "^4.17.6",
"@types/react": ">=18.0.0",
"amazon-cognito-identity-js": "^6.0.0",
"husky": "^8.0.3",
"husky": "^9.0.7",
"lint-staged": "^15.2.0",
"msw": "^2.1.4",
"npm-run-all": "^4.1.5",
Expand Down
6 changes: 5 additions & 1 deletion src/model/get-current-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import sessionToAuthAccess from "./session-to-auth-access";

type UserBundle<TUser> = {
readonly cognitoUser: CognitoUser;
readonly authUser: TUser;
readonly authUser: TUser & {
readonly isMfaEnabled: boolean;
};
};

type UserParser<TUser> = (data: UserData, session: CognitoUserSession) => TUser;
Expand Down Expand Up @@ -39,6 +41,8 @@ async function baseGetUserData<TUser>(
resolve({
...parseUser(data, session),
...sessionToAuthAccess(session),
// Typing is wrong for lib - PreferredMfaSetting should be string | undefined
isMfaEnabled: data.PreferredMfaSetting !== undefined,
});
},
{ bypassCache },
Expand Down
4 changes: 3 additions & 1 deletion src/model/session-to-auth-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function sessionToAuthAccess(session: CognitoUserSession) {
};
}

type AuthAccess = ReturnType<typeof sessionToAuthAccess>;
type AuthAccess = ReturnType<typeof sessionToAuthAccess> & {
readonly isMfaEnabled: boolean;
};

export type { AuthAccess };
export default sessionToAuthAccess;
2 changes: 1 addition & 1 deletion src/signed-in-auth-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function createSignedInAuthState<TUser>({
parseUser,
user,
),
disableMfa: partial(disableMfa, setInternalAuthState, parseUser, user),
disableMfa: async () => disableMfa(setInternalAuthState, parseUser, user),
getMfaCodeUrl: partial(getMfaCodeUrl, mfaIssuer, user),
refreshUser,
verifyEmailAddress: partial(
Expand Down

0 comments on commit 2e699b1

Please sign in to comment.