fix: Don't store token in SDK by default (#9704)
This commit is contained in:
1 parent
d8e3e04895
commit
abe003a5d6
3 files changed
+24
-7
No files matched your search
@@ -82,6 +82,18 @@ const server = setupServer(
|
|||||||
statusText: "Internal Server Error",
|
statusText: "Internal Server Error",
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
http.get(`${baseUrl}/nostore`, ({ request }) => {
|
||||||
|
if (!request.headers.get("authorization")) {
|
||||||
|
return HttpResponse.json({
|
||||||
|
test: "test",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpResponse(null, {
|
||||||
|
status: 500,
|
||||||
|
statusText: "Internal Server Error",
|
||||||
|
})
|
||||||
|
}),
|
||||||
http.all("*", ({ request, params, cookies }) => {
|
http.all("*", ({ request, params, cookies }) => {
|
||||||
return new HttpResponse(null, {
|
return new HttpResponse(null, {
|
||||||
status: 404,
|
status: 404,
|
||||||
@@ -185,11 +197,11 @@ describe("Client", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Authrized requests", () => {
|
describe("Authrized requests", () => {
|
||||||
it("should set the token in memory by default", async () => {
|
it("should not store the token by default", async () => {
|
||||||
const token = "token-123" // Eg. from a response after a successful authentication
|
const token = "token-123" // Eg. from a response after a successful authentication
|
||||||
client.setToken(token)
|
client.setToken(token)
|
||||||
|
|
||||||
const resp = await client.fetch<any>("jwt")
|
const resp = await client.fetch<any>("nostore")
|
||||||
expect(resp).toEqual({ test: "test" })
|
expect(resp).toEqual({ test: "test" })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -301,7 +301,8 @@ export class Client {
|
|||||||
const hasSession = hasStorage("sessionStorage")
|
const hasSession = hasStorage("sessionStorage")
|
||||||
|
|
||||||
const storageMethod =
|
const storageMethod =
|
||||||
this.config.auth?.jwtTokenStorageMethod || (hasLocal ? "local" : "memory")
|
this.config.auth?.jwtTokenStorageMethod ||
|
||||||
|
(hasLocal ? "local" : "nostore")
|
||||||
const storageKey =
|
const storageKey =
|
||||||
this.config.auth?.jwtTokenStorageKey || this.DEFAULT_JWT_STORAGE_KEY
|
this.config.auth?.jwtTokenStorageKey || this.DEFAULT_JWT_STORAGE_KEY
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export type Config = {
|
|||||||
auth?: {
|
auth?: {
|
||||||
type?: "jwt" | "session"
|
type?: "jwt" | "session"
|
||||||
jwtTokenStorageKey?: string
|
jwtTokenStorageKey?: string
|
||||||
jwtTokenStorageMethod?: "local" | "session" | "memory"
|
jwtTokenStorageMethod?: "local" | "session" | "memory" | "nostore"
|
||||||
}
|
}
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
@@ -21,15 +21,19 @@ export type Config = {
|
|||||||
|
|
||||||
export type FetchParams = Parameters<typeof fetch>
|
export type FetchParams = Parameters<typeof fetch>
|
||||||
|
|
||||||
export type ClientHeaders =
|
export type ClientHeaders = Record<
|
||||||
Record<string, string | null | {
|
string,
|
||||||
|
| string
|
||||||
|
| null
|
||||||
|
| {
|
||||||
/**
|
/**
|
||||||
* Tags to cache data under for Next.js applications.
|
* Tags to cache data under for Next.js applications.
|
||||||
*
|
*
|
||||||
* Learn more in [Next.js's documentation](https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag).
|
* Learn more in [Next.js's documentation](https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag).
|
||||||
*/
|
*/
|
||||||
tags: string[]
|
tags: string[]
|
||||||
}>
|
}
|
||||||
|
>
|
||||||
|
|
||||||
export type FetchInput = FetchParams[0]
|
export type FetchInput = FetchParams[0]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user