-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[email protected] breaks client auth with edge functions #881
Comments
I ran into this today as well when I deployed a new version of an existing edge function and immediately started getting Auth errors.
|
Looks like it's affecting me as well.
|
Wasted 4 hours debugging this... 🥲 |
LMAO, you were not alone. I restarted the database, and I reset my jwt tokens lmao. |
I confirm I have the same issue and rolling back to Seems related to |
Here's the solution: via Discord:
|
Here is my observation: PR #876 adds a check for Previously, without the new PR code, it would have just made a fetch request to the auth backend using /* https://github.com/supabase/auth-js/blob/v2.63.1/src/GoTrueClient.ts#L1182-L1185 */
return await _request(this.fetch, 'GET', `${this.url}/user`, {
headers: this.headers,
jwt: data.session?.access_token ?? undefined,
xform: _userResponse,
}) And if you look at /* https://github.com/supabase/auth-js/blob/v2.63.1/src/lib/fetch.ts#L127-L143 */
export async function _request(
fetcher: Fetch,
method: RequestMethodType,
url: string,
options?: GotrueRequestOptions
) {
const headers = {
...options?.headers,
}
if (!headers[API_VERSION_HEADER_NAME]) {
headers[API_VERSION_HEADER_NAME] = API_VERSIONS['2024-01-01'].name
}
if (options?.jwt) {
headers['Authorization'] = `Bearer ${options.jwt}`
}
...
const data = await _handleRequest(
fetcher,
method,
url + queryString,
{
headers,
noResolveJson: options?.noResolveJson,
},
{},
options?.body
) |
Seems like a pretty major change for such a minor version bump. This broke my app too. |
+1 This broke my app too. I was deploying new edge functions in dev today and thought I was having the worst coding day ever for an hour or two. Because my edge functions don't have a pinned supabase library version the new code was getting picked up whenever I would deploy a new version of an edge function. I'm sure many people like me have used the supabase edge function auth docs as a starting point for how to get authenticated user data within an edge function. This suggests that you can leave the I ended up having to go through every edge function and patch it like this
I'm confused why the supabase client needs the same JWT twice. I don't know all of the intended uses of the I think my take away here is to not do this in my edge function code
and instead do this
and then only upgrading when I explicitly intend to move to a new version. |
I'm going to move this to the auth repository as it seems to be the underlying auth-js release is the issue. Hopefully the right move... |
@kangmingtay Does the supabase-js team know about this fix? Users are still running into the issue on Edge functions and your fix here has not been merged with supabase-js yet, or released. |
You can use any version below 2.42.4. Eg: import { createClient } from 'https://esm.sh/@supabase/[email protected]'; |
Sure and that's what I'm telling users that come to discord, or github and I see them. Or just use getUser(jwt) with the jwt from the header. |
Just to reinforce what GaryAustin1 is saying... When I wrote in to support with this issue I got back:
In reference to calling It's a big breaking issue for anyone who copied code form the JavaScript edge function auth docs. It's insidious in that it only shows up when you deploy a new version of your edge function and only if you are using the import line from the docs which just references Then you spend a lot of time trying to figure out how you completely broke your edge function with whatever change you made. |
Bug report
Describe the bug
When I get the authorization header from the client in an edge function I'm unable to make a supabase client with the newest version of supabase-js (using deno edge functions). The behavior doesn't happen on 2.42.4 and below. I have rolled back but I wanted to bring this to your attention.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Expected behavior
Able to get user auth details. See code snippet at bottom of how I typically do that.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
Additional context
`import { corsHeaders } from '../_shared/cors.ts'
import { createClient } from "supabase-js"
import { createSupabaseClient } from '../_shared/supabaseClient.ts'
Deno.serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
const authHeader = req.headers.get('Authorization')!
const supabaseClient = createSupabaseClient(authHeader)
// Get the session or user object
const { data } = await supabaseClient.auth.getUser()
const user = data.user
if (!user) {
throw new Error('User is null');
}
}`
and here is the definition for my client function:
`import { createClient, SupabaseClient } from "supabase-js"
export function createSupabaseClient(authHeader: string): SupabaseClient {
return createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{ global: { headers: { Authorization: authHeader } } }
);
}`
The text was updated successfully, but these errors were encountered: