diff --git a/examples/auth/app/page.tsx b/examples/auth/app/page.tsx index f0ee69a91a..49c4c49291 100644 --- a/examples/auth/app/page.tsx +++ b/examples/auth/app/page.tsx @@ -15,19 +15,6 @@ interface UserAccumulator { [key: number]: User[] } -const fetchWrapper = async (...args: Parameters) => { - const queryParams = new URLSearchParams(window.location.search) - const org_id = queryParams.get(`org_id`) - const modifiedArgs = [...args] - if (org_id) { - const headers = new Headers((modifiedArgs[1] as RequestInit)?.headers || {}) - headers.set(`Authorization`, org_id) - modifiedArgs[1] = { ...(modifiedArgs[1] as RequestInit), headers } - } - const response = await fetch(...(modifiedArgs as [RequestInfo, RequestInit?])) - return response -} - const usersShape = (): ShapeStreamOptions => { if (typeof window !== `undefined`) { const queryParams = new URLSearchParams(window.location.search) @@ -37,7 +24,9 @@ const usersShape = (): ShapeStreamOptions => { `/shape-proxy/users?org_id=${org_id}`, window.location.origin ).href, - fetchClient: fetchWrapper, + headers: { + Authorization: org_id || ``, + }, } } else { return { diff --git a/website/docs/guides/auth.md b/website/docs/guides/auth.md index 2bf73a7328..d25bc90aa8 100644 --- a/website/docs/guides/auth.md +++ b/website/docs/guides/auth.md @@ -48,27 +48,14 @@ When using the [Typescript client](/docs/api/clients/typescript), you can pass a In the client: ```tsx -const fetchWrapper = async (...args: Parameters) => { +const usersShape = (): ShapeStreamOptions => { const user = loadCurrentUser() - const modifiedArgs = [...args] - const headers = new Headers( - (modifiedArgs[1] as RequestInit)?.headers || {} - ) - - // Set authorization token - headers.set(`Authorization`, `Bearer ${user.token}`) - - modifiedArgs[1] = { ...(modifiedArgs[1] as RequestInit), headers } - const response = await fetch( - ...(modifiedArgs as [RequestInfo, RequestInit?]) - ) - return response -} -const usersShape = (): ShapeStreamOptions => { return { url: new URL(`/api/shapes/users`, window.location.origin).href, - fetchClient: fetchWrapper, + headers: { + authorization: `Bearer ${user.token}` + } } }