-
Notifications
You must be signed in to change notification settings - Fork 331
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
getToken method returns null right after isSIgnedIn becomes true #2266
Comments
@kylegwalsh , Having seen the video and checked the behaviour myself to double check, Since you mentioned that you actually check the value of |
Hi @desiprisg, my code uses
// Get the user data from our DB
const { data } = trpc.user.get.useQuery(undefined, {
// Don't enable the query until the clerk user is defined
enabled: !!isSignedIn,
});
import { useAuth } from '@clerk/clerk-expo';
import { config } from '@hlp/config';
import { trpc } from '@hlp/core/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { httpBatchLink } from '@trpc/client/links/httpBatchLink';
import React, { useState } from 'react';
import superjson from 'superjson';
/** Adds TRPC and react-query functionality to the app */
export const QueryProvider = ({ children }: any) => {
const { getToken } = useAuth();
// Initialize query client and trpc client
const [queryClient] = useState(() => new QueryClient());
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url: `${config.api.url}/trpc/`,
async headers() {
/** Retrieve auth token from storage */
const token = await getToken({
template: 'default',
});
console.log('CLERK TOKEN', token);
return {
// Attach auth header if we have a token
...(token && {
Authorization: `Bearer ${token}`,
}),
};
},
}),
],
transformer: superjson,
})
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
}; So, the I just attempted to upgrade to the latest clerk version to see if the issues still persist, but I'm seeing a CORS error due to an expo header (I never saw this before, so I'm not sure what introduced it). I'll have to dig into this more before I can determine if I'm still seeing the issue.
|
We also have pages protected by whose useEffects are triggered while await getToken() returns null (same situation as above - directly after the user signs in and gets redirected). Is there active work on this issue / what is the best practice here to prevent a double fetch? |
Note Those header(s) are coming from the Expo SDK. javascript/packages/expo/src/singleton.ts Lines 47 to 53 in 69df1ab
We can remove these, and publish a new version. Additionally, the CORS suggests that you're using Clerk-expo from a browser, is that right @kylegwalsh? Can you help us understand your development flow a bit? Clerk-expo via the browser is not exactly a supported use case yet, though we do have Support for Expo Web on our roadmap. |
@thiskevinwang That would make sense. We've actually been using Happy to expand on our development flow as well. We actually created a single expo codebase that works on every platform (ios, android, and web). Most of the libraries that we're using support that setup, however we do have to occasionally create two separate files (index.web.ts vs. index.native.ts) to import separate packages based on platform. I can definitely modify the setup to import |
@kylegwalsh I've opened a PR to remove these headers - #3326 While that is in-review, you can also try |
Hey @kylegwalsh this should be fixed in Give that a shot, and feel free to reopen this issue if the error persists! npm install @clerk/clerk-expo@latest |
Preliminary Checks
I have reviewed the documentation: https://clerk.com/docs
I have searched for existing issues: https://github.com/clerk/javascript/issues
I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)
This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Reproduction / Replay Link
https://jam.dev/c/3bce6734-c313-4b82-a638-4022254bfb7a
Publishable key
pk_test_Y2xlcmsuY3Jpc3Auc2Vhc25haWwtOTEubGNsLmRldiQ
Description
Steps to reproduce:
useSignIn()
hookgetToken()
from theuseAuth()
hook once the user logs in (key off of theisSignedIn
boolean)Expected behavior:
I would expect
getToken()
to return the token the moment clerk indicates thatisSignedIn
is true. This is how the library behaved in version0.10.6
of clerk-expo (and it's related clerk-react version).Actual behavior:
getToken()
returnsnull
right after the user is signed in (a race condition). This causes a cascade of undesired behaviors in my particular app because I expect token to exist right after clerk informs me that the userisSignedIn
.Environment
The text was updated successfully, but these errors were encountered: