-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auth Server SDK: Stores new auth material cookies (#817)
Stores new auth material cookies
- Loading branch information
1 parent
63ea1dc
commit fe06a3e
Showing
20 changed files
with
247 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@crossmint/common-sdk-auth": patch | ||
--- | ||
|
||
Improves type naming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@crossmint/server-sdk": minor | ||
--- | ||
|
||
Adds storeAuthMaterial to store auth material in cookies and does so in getSession |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@crossmint/client-sdk-react-ui": patch | ||
--- | ||
|
||
Use new type names for auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type CookieOptions = { | ||
name: string; | ||
value: string; | ||
expiresAt?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./user"; | ||
export * from "./authmaterial"; | ||
export * from "./errors"; | ||
export * from "./cookies"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { type Crossmint, CrossmintApiClient } from "@crossmint/common-sdk-base"; | |
import { type AuthMaterialBasic, CrossmintAuthenticationError } from "@crossmint/common-sdk-auth"; | ||
import * as cookiesUtils from "./utils/cookies"; | ||
import * as jwtUtils from "./utils/jwt"; | ||
import type { GenericRequest } from "./types/request"; | ||
import type { GenericRequest, GenericResponse } from "./types/request"; | ||
|
||
vi.mock("@crossmint/common-sdk-base"); | ||
vi.mock("./utils/cookies"); | ||
|
@@ -15,6 +15,7 @@ describe("CrossmintAuth", () => { | |
const mockCrossmint = { projectId: "test-project-id" }; | ||
const mockApiClient = { | ||
baseUrl: "https://api.crossmint.com", | ||
get: vi.fn(), | ||
post: vi.fn(), | ||
}; | ||
|
||
|
@@ -72,6 +73,10 @@ describe("CrossmintAuth", () => { | |
|
||
expect(result).toEqual({ | ||
jwt: "mock.jwt.token", | ||
refreshToken: { | ||
secret: "mock-refresh-token", | ||
expiresAt: "", | ||
}, | ||
userId: "user123", | ||
}); | ||
}); | ||
|
@@ -83,15 +88,23 @@ describe("CrossmintAuth", () => { | |
json: () => | ||
Promise.resolve({ | ||
jwt: "new.jwt.token", | ||
refresh: "new-refresh-token", | ||
refresh: { | ||
secret: "new-refresh-token", | ||
expiresAt: "2023-12-31T23:59:59Z", | ||
}, | ||
user: { id: "user456" }, | ||
}), | ||
ok: true, | ||
}); | ||
|
||
const result = await crossmintAuth.getSession(mockRequest as GenericRequest); | ||
|
||
expect(result).toEqual({ | ||
jwt: "new.jwt.token", | ||
refreshToken: { | ||
secret: "new-refresh-token", | ||
expiresAt: "2023-12-31T23:59:59Z", | ||
}, | ||
userId: "user456", | ||
}); | ||
expect(mockApiClient.post).toHaveBeenCalledWith( | ||
|
@@ -124,4 +137,39 @@ describe("CrossmintAuth", () => { | |
); | ||
}); | ||
}); | ||
|
||
describe("getUser", () => { | ||
it("should fetch user data for a given external user ID", async () => { | ||
const mockExternalUserId = "external-user-123"; | ||
const mockUserData = { id: "user456", email: "[email protected]" }; | ||
mockApiClient.get.mockResolvedValue({ | ||
json: () => Promise.resolve(mockUserData), | ||
}); | ||
|
||
const result = await crossmintAuth.getUser(mockExternalUserId); | ||
|
||
expect(result).toEqual(mockUserData); | ||
expect(mockApiClient.get).toHaveBeenCalledWith( | ||
`api/2024-09-26/sdk/auth/user/${mockExternalUserId}`, | ||
expect.any(Object) | ||
); | ||
}); | ||
}); | ||
|
||
describe("storeAuthMaterial", () => { | ||
it("should call setAuthCookies with the provided response and auth material", () => { | ||
const mockResponse = {} as GenericResponse; | ||
const mockAuthMaterial = { | ||
jwt: "new.jwt.token", | ||
refreshToken: { | ||
secret: "new-refresh-token", | ||
expiresAt: "2023-12-31T23:59:59Z", | ||
}, | ||
}; | ||
|
||
crossmintAuth.storeAuthMaterial(mockResponse, mockAuthMaterial); | ||
|
||
expect(cookiesUtils.setAuthCookies).toHaveBeenCalledWith(mockResponse, mockAuthMaterial); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.