Skip to content

Commit

Permalink
Merge pull request #20 from kinde-oss/peter/test-callback
Browse files Browse the repository at this point in the history
Peter/test callback
  • Loading branch information
peterphanouvong authored Sep 9, 2024
2 parents 6af02f4 + f9bd798 commit 8b81adc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v1.1.2](https://github.com/kinde-oss/kinde-remix-sdk/compare/v1.1.1...v1.1.2)

> 6 September 2024
- chore: release v1.1.2 [`6af02f4`](https://github.com/kinde-oss/kinde-remix-sdk/commit/6af02f465478d9c06d1cdaf691fc371c8fa353c4)

#### [v1.1.1](https://github.com/kinde-oss/kinde-remix-sdk/compare/v1.1.0...v1.1.1)

> 28 August 2024
Expand Down
5 changes: 1 addition & 4 deletions src/handle-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ export const handleAuth = async (request, route, options) => {
"Set your post login redirect URL in your environment variables.";
const headers = generateCookieHeader(request, cookies);

/**
* @type {any}
*/
const user = await sessionManager.getSessionItem("user");
const user = await kindeClient.getUser(sessionManager);

options?.onRedirectCallback?.({ user });

Expand Down
19 changes: 16 additions & 3 deletions tests/handle-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("handleAuth", () => {

it("should handle login requests", async () => {
const requestEvent = new Request(
"http://localhost/oop/?returnTo=/redirect",
"http://localhost/oop/?returnTo=/redirect"
);

const loginMock = vi.fn().mockImplementation(async () => {
Expand All @@ -33,7 +33,7 @@ describe("handleAuth", () => {

it("should handle register requests", async () => {
const requestEvent = new Request(
"http://localhost/oop/?returnTo=/redirect",
"http://localhost/oop/?returnTo=/redirect"
);

const registerMock = vi.fn().mockImplementation(async () => {
Expand Down Expand Up @@ -71,11 +71,24 @@ describe("handleAuth", () => {
const callback = vi.fn().mockImplementation(async () => {
return new URL("http://localhost/logged-out");
});

const getUserMock = vi.fn().mockImplementation(async () => {
return {
family_name: "Test",
given_name: "Tom",
picture:
"https://lh3.googleusercontent.com/a/ACg8ocLSV5BzAauEPx7KiftgzBclIOZN7AGwr-Yp194XPMaCEqAr0e3e=s96-c",
email: "[email protected]",
id: "kp:a912075d0172416787920727ddcf087e",
};
});

kindeClient.handleRedirectToApp = callback;
kindeClient.getUser = getUserMock;
const res = await handleAuth(requestEvent, "callback");
expect(res?.status).toBe(302);
expect(res?.headers.get("location")).toBe(
"http://localhost:3000/test-login",
"http://localhost:3000/test-login"
);
});
});

0 comments on commit 8b81adc

Please sign in to comment.