wee-brown
wee-brownโ€ข3y ago

Can't refetch Auth

I'm not sure if this is a refine or react problem, but the Router Provider keeps thinking I'm unauthenticated, but I'm not. Below is my code:
const { isFetching, refetch: checkAuth } = useAuthenticated();

const { mutate } = useUpdate();

useEffect(() => {
if (isFetching) return;

if (teamId && membershipId && secret && userId) {
mutate(
{
dataProviderName: "teams",
resource: teamsResources.membershipStatus,
id: teamId,
values: { membershipId, secret, userId },
},
{
onSuccess: async () => {
try {
await checkAuth();

list(Constants.collections.organizations);
} catch (e) {
console.error(e);
}
},
}
);
}
}, [isFetching, membershipId, secret, teamId, userId]);
const { isFetching, refetch: checkAuth } = useAuthenticated();

const { mutate } = useUpdate();

useEffect(() => {
if (isFetching) return;

if (teamId && membershipId && secret && userId) {
mutate(
{
dataProviderName: "teams",
resource: teamsResources.membershipStatus,
id: teamId,
values: { membershipId, secret, userId },
},
{
onSuccess: async () => {
try {
await checkAuth();

list(Constants.collections.organizations);
} catch (e) {
console.error(e);
}
},
}
);
}
}, [isFetching, membershipId, secret, teamId, userId]);
Any ideas?
14 Replies
harsh-harlequin
harsh-harlequinโ€ข3y ago
Hey @geekdev, sorry to hear you're having an issue. I'm checking now and trying to have a reproduction.
wee-brown
wee-brownOPโ€ข3y ago
Btw, the user is not authenticated when reaching the page, but the mutate is supposed to create a session so the checkAuth is successful
Omer
Omerโ€ข3y ago
Hey @geekdev ๐Ÿ‘‹, Could you share your checkAuth function?
wee-brown
wee-brownOPโ€ข3y ago
checkAuth: async () => {
console.log("checkAuth");
await account.get();
},
checkAuth: async () => {
console.log("checkAuth");
await account.get();
},
๐Ÿ˜‰ as you can guess, I'm connecting to Appwrite
Omer
Omerโ€ข3y ago
GitHub
refine/App.tsx at next ยท refinedev/refine
Build your React-based CRUD applications, without constraints. - refine/App.tsx at next ยท refinedev/refine
wee-brown
wee-brownOPโ€ข3y ago
btw, await account.get(); will either return the session or throw an exception...so that return Promise.reject(); will never be called but i have tried your suggestion and it's the same result
Omer
Omerโ€ข3y ago
This code confused me. Can you explain a little bit? ๐Ÿ‘€
wee-brown
wee-brownOPโ€ข3y ago
Appwrite uses teams for group permissions. A user can invite another user to a team and they'll get an email with a link that includes a secret. This page handles that link and calls the update team membership status API (the mutate call). That API call will also create a session
Omer
Omerโ€ข3y ago
Oh I got it. As a workaround you can manually invalidate the state https://github.com/refinedev/refine/blob/next/packages/core/src/contexts/auth/index.tsx#L18 Also could you create a GitHub issue? We'll fix it monday ๐Ÿš€
wee-brown
wee-brownOPโ€ข3y ago
GitHub
[BUG] Can't refetch Auth ยท Issue #3019 ยท refinedev/refine
Describe the bug My app has another way to authenticate the user outside of the authProvider's login method. After successfully logging in without the authProvider, I try to call refetch() ...
wee-brown
wee-brownOPโ€ข3y ago
this worked! Thanks! now I need to figure out why my mutate is being fired twice... ๐Ÿ˜…
Omer
Omerโ€ข3y ago
GitHub
[BUG] Request api two times ยท Issue #2978 ยท refinedev/refine
Describe the bug When requesting API, always request API two times Steps To Reproduce Open firebug Network Open posts list: https://zzmiwzvxm--github--3000.local.webcontainer.io/posts => req...
Omer
Omerโ€ข3y ago
Maybe could help ๐Ÿ™‚
wee-brown
wee-brownOPโ€ข3y ago
Thanks! Weird react ๐Ÿ˜‘

Did you find this page helpful?