Comments (9)
I can confirm that your changes solve my issue, thank you @alicanerdurmaz
from refine.
Hello @jackprogramsjp, I created a new project and it seems to be no issue.
Can you please provide us your authProvider
and route
implementations? If it's possible, the full project would be awesome for deep-dive debugging.
Also which browser are u using? you can use pnpm run refine whoami
to see your browser version.
from refine.
I have the same issue, using the next.js / supabase scaffold. I usually notice this functionality about one hour after I close the tab and come back to the project.
I realize my issue is slightly different to the original issue because I'm using Supabase, but I believe it stems from the same bug.
From debugging it looks like the reason is because
- The default
auth-provider.server.ts
is checking if the user is authenticated, from the cookie, which returnstrue
, tries to load the resource/page. - The default
auth-provider.ts
is checking if the user is authenticated with supabase js client, which returns an empty user object, and redirects to/login
.
@alicanerdurmaz I can invite you to the project that you can use to debug if that helps?
from refine.
@alicanerdurmaz Changing the auth-provider.server.ts
to the following, seems to fix the issue, but there's probably a better way to fix this issue using the supabase js sdk. I commented the additions which fix the issue with ADDED
import { AuthBindings } from "@refinedev/core";
import { cookies } from "next/headers";
// ADDED
function decodeJWTPayload (token: string) {
return JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
}
export const authProviderServer: Pick<AuthBindings, "check"> = {
check: async () => {
const cookieStore = cookies();
const auth = cookieStore.get("token");
// ADDED
let expiryTimestamp = auth?.value ? decodeJWTPayload(auth.value).exp * 1000 : Infinity
let isStoredTokenValid = Date.now() - expiryTimestamp <= 0
if (auth && isStoredTokenValid) {
return {
authenticated: true,
};
}
return {
authenticated: false,
logout: true,
redirectTo: "/login",
};
},
};
from refine.
@mschinis I could reproduce the bug, thanks for the solutions. Your solution seems valid but I want to investigate more. I believe Supabase's SDK has more viable solutions https://supabase.com/docs/guides/auth/server-side/creating-a-client
I will keep you informed.
from refine.
Hello again @mschinis and @jackprogramsjp
I fixed the supabase auth provider and we will release the fix for create refine-app
as soon as possible, but you can fix your project while waiting for the release.
You can find the finished project here
keypoints:
- we need to create
authProviderServer
with"@supabase/ssr"
package. - Supabase middleware to handle all cookie processes and refreshing the Auth token.
- Also I did a couple of fixes on
authProviderClient
- I have created supabase client from
"@supabase/ssr"
package. - Also I made changes on
authProvider
. You can copy and paste your project to see DIFF in git.
Please feel free to let me know if you find any issues or if you have any suggestions for improvements to the code.
from refine.
Hi @alicanerdurmaz , thanks for the quick turnaround. I've implemented your changes in my project and I'll get back to you, once I do a thorough testing.
In general, your approach make sense. Couple of quick comments:
- There's a small typo
contants.ts
instead ofconstants.ts
- Here, the
supabaseBrowserClient.auth.setSession
method returns a promise, but there's noawait
, was this a conscious decision?
from refine.
Hi @alicanerdurmaz , thanks for the quick turnaround. I've implemented your changes in my project and I'll get back to you, once I do a thorough testing.
In general, your approach make sense. Couple of quick comments:
- There's a small typo
contants.ts
instead ofconstants.ts
- Here, the
supabaseBrowserClient.auth.setSession
method returns a promise, but there's noawait
, was this a conscious decision?
Thanks! @mschinis. You are right, we need to await the supabaseBrowserClient.auth.setSession
.
from refine.
Hello again @jackprogramsjp, we released a fix for appwrite. You can see changed files here.
If you have any questions please feel free to ask.
from refine.
Related Issues (20)
- [FEAT] Pro Components for Ant Design HOT 1
- [DOC] Tutorial with Material UI is broken
- [FEAT] TS-Rest Data Provider HOT 2
- [BUG] default MUI theme shrinks the main content when sidebar is open initially, but not whenever the sidebar is opened after that HOT 2
- [FEAT] Make it EASY to code for medusa
- [BUG] `invalidates` prop of `useUpdateMany` doesn't work
- [BUG] redirect in useForm refineCoreProps doens't work HOT 4
- [BUG] Typo in examples/app-crm-minimal code snippets graphql/queries.ts HOT 4
- [BUG] `<DateField value={undefined} />` is still displaying the date HOT 6
- [BUG] Element Selector in Devtools causing crash through `e.getBoundingClientRect is not a function` HOT 5
- [FEAT] after generating resources with `refine add resource` command, `@refinedev/inferencer` package is missing.
- [BUG] Type error when functions are passed to `optionLabel` and `optionValue` in `useSelect`
- [BUG] `refine add resource` generating invalid React component name
- [BUG]Supabase data provider returns wrong sorted list for foreign table colmun HOT 2
- [BUG] Nested CrudFilters values with Supabase not correctly parsed HOT 2
- [FEAT] replace `preferred-pm` with `package-manager-detector` HOT 2
- [BUG] Keycloak auth not working, redirecting back to login HOT 1
- [FEAT] Add support to `and`, `or`, `between`, `null` and `nnull` operators in `@refinedev/appwrite` HOT 2
- [BUG] Unable to implement custom queryclient for invalidating custom queries HOT 1
- [BUG] `queryOptions.enabled` causes `undefined` request to be sent in `useForm`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from refine.