Skip to content

Commit

Permalink
Merge pull request #11 from kodado/typescript-improvements
Browse files Browse the repository at this point in the history
Typescript improvements
  • Loading branch information
Fubinator committed May 8, 2024
2 parents 5d729ad + 742d563 commit 5e5700d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/auth/AuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
EmailAndPasswordRequiredError,
AlreadySignedInError,
NotSignedInError,
WrongCredentialsError,
} from "../errors/authErrors";

import {
Expand Down Expand Up @@ -72,7 +73,7 @@ export class AuthClient {
});

if (!session) {
return;
throw new WrongCredentialsError();
}

if (session instanceof CognitoUserSession) {
Expand Down Expand Up @@ -122,6 +123,10 @@ export class AuthClient {
};
}

if (!this.user) {
throw new WrongCredentialsError();
}

return this.user;
}

Expand Down Expand Up @@ -225,7 +230,7 @@ export class AuthClient {
this.session = null;
this.keys = null;

return this.cognitoClient.deleteCognitoUser(user);
await this.cognitoClient.deleteCognitoUser(user);
}

async getCurrentAuthorizationToken() {
Expand Down
15 changes: 13 additions & 2 deletions test/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,19 @@ describe("deleteUser", () => {
email: "auth-lib-user@turingpoint.de",
password: "Abcd1234!",
});
const success = await client.auth.deleteUser();

expect(success).toBe(true);
await client.auth.deleteUser();

try {
await client.auth.signIn({
email: "auth-lib-user@turingpoint.de",
password: "Abcd1234!",
});
expect(false).toBe(true);
} catch (e) {
if (e instanceof WrongCredentialsError) {
expect(true).toBe(true);
}
}
});
});
4 changes: 3 additions & 1 deletion test/bulkRevokeItem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ describe("bulkRevoke", () => {
id: ids[0],
});
} catch (e) {
expect(e.message).toBe("Item not found.");
if (e instanceof Error) {
expect(e.message).toBe("Item not found.");
}
}
client.auth.signOut();
});
Expand Down

0 comments on commit 5e5700d

Please sign in to comment.