Rafael Hengles
Rafael Hengles
Explore posts from servers
RRefine
Created by unwilling-turquoise on 5/3/2023 in #ask-any-question
dynamic i18n resource route prefix path
@kapa.ai Thank you, but the problem is that the :lang parameter is dynamic, and as far as I understand, I need to use useParams() hook from "react-router-dom" v6 to get the :lang value, but this hook must be called inside the <Route path=":lang"> as far as I understand, which is itself a child of the <Refine> component. Maybe I do need to create my own provider so I can send this lang parameter up the component tree ?
21 replies
RRefine
Created by wise-white on 5/3/2023 in #ask-any-question
dynamic i18n resource route prefix path
@kapa.ai Yeah this useForm() hook is unrelated, but this General Concepts link is good
21 replies
RRefine
Created by rival-black on 5/3/2023 in #ask-any-question
dynamic i18n resource route prefix path
@salihozdemir Thank you, but the problem is that the lang is dynamic, and as far as I understand, I need to use useParams() to get the lang, but this hook must be called inside the <Route path=":lang"> AFAICT
21 replies
RRefine
Created by exotic-emerald on 5/3/2023 in #ask-any-question
dynamic i18n resource route prefix path
@kapa.ai Thank you! This doc page: https://refine.dev/docs/tutorial/understanding-resources/index Says this:
```js
({ name: "blog_posts", edit: "/blog-posts/edit/:id/:version", }) `` > These additional parameters, except for the id parameter, can be passed to the components or hooks using meta properties. The existing parameters in the URL will be used by default when handling the navigation. I don't know where or how these meta` properties are defined, and there are no other mentions on that page and I didn't find any relevant links on that page.
21 replies
RRefine
Created by conventional-tan on 3/20/2023 in #ask-any-question
AuthPage does not handle any errors
that's impressive !
6 replies
RRefine
Created by ambitious-aqua on 3/20/2023 in #ask-any-question
Data provider requests in loop when using Vite
Thank you, the part that was giving me an error was because I wasn't using the useGetIdentity hook (because I didn't read the docs enough 😅 )
11 replies
RRefine
Created by conscious-sapphire on 3/20/2023 in #ask-any-question
Data provider requests in loop when using Vite
It appears I'm using the auth provider wrong, I'll fix that and see what I get
11 replies
RRefine
Created by environmental-rose on 3/20/2023 in #ask-any-question
Data provider requests in loop when using Vite
Umm I'm almost done creating the sandbox, but now I can't integrate the backend because I don't have it in https, the certificate is not set up yet. I'll see if I can mock the backend...
11 replies
RRefine
Created by harsh-harlequin on 3/20/2023 in #ask-any-question
Data provider requests in loop when using Vite
Thank you, I'll do that. But this is the Dev environment, I just don't have the backend to run locally
11 replies
RRefine
Created by helpful-purple on 3/20/2023 in #ask-any-question
Data provider requests in loop when using Vite
Just for completeness, when I use the generated code, the page loads the list 202 times, but it's faster. When I use the <HeadlessListInferencer /> directly, the page flashes during each load, making it very hard to me to wait and see if the loop eventually stops. And also it is hammering our poor backend server...
11 replies
RRefine
Created by optimistic-gold on 3/17/2023 in #ask-any-question
query data cannot be undefined
Awesome, that was it! Thanks for the quick reply! 💯
16 replies
RRefine
Created by conscious-sapphire on 3/17/2023 in #ask-any-question
query data cannot be undefined
ah good!
16 replies
RRefine
Created by other-emerald on 3/17/2023 in #ask-any-question
query data cannot be undefined
check: async (request) => {
let user = undefined;
if (request) {
const hasCookie = request.headers.get("Cookie");
if (hasCookie) {
const parsedCookie = cookie.parse(request.headers.get("Cookie"));
user = parsedCookie[COOKIE_NAME];
}
} else {
user = getCookieIdentity();
}

const { pathname = undefined } = request ? new URL(request.url) : {};

if (!user) {
return {
authenticated: false,
error: new Error("Unauthenticated"),
logout: true,
redirectTo: `/login${pathname ? `?to=${pathname}` : ``}`,
};
}

return {
authenticated: true,
};
},
getPermissions: async () => null,
getIdentity: async () => getCookieIdentity(),
};
check: async (request) => {
let user = undefined;
if (request) {
const hasCookie = request.headers.get("Cookie");
if (hasCookie) {
const parsedCookie = cookie.parse(request.headers.get("Cookie"));
user = parsedCookie[COOKIE_NAME];
}
} else {
user = getCookieIdentity();
}

const { pathname = undefined } = request ? new URL(request.url) : {};

if (!user) {
return {
authenticated: false,
error: new Error("Unauthenticated"),
logout: true,
redirectTo: `/login${pathname ? `?to=${pathname}` : ``}`,
};
}

return {
authenticated: true,
};
},
getPermissions: async () => null,
getIdentity: async () => getCookieIdentity(),
};
16 replies
RRefine
Created by rare-sapphire on 3/17/2023 in #ask-any-question
query data cannot be undefined
export const authProvider: AuthBindings = {
login: async ({ email: username, password, remember }) => {
try {
const result = await dataProvider.create({
resource: 'auth/login',
variables: {
username,
password,
},
meta: { noAuth: true },
});
console.warn(`authProvider login result`, result);
const { data: { access_token, admin } } = result;
setCookieIdentity({ access_token, admin });
return {
success: true,
redirectTo: "/",
};
} catch (error) {
console.warn(`authProvider login error`, error)
return {
success: false,
error: error as Error,
};
}

},
logout: async () => {
removeCookieIdentity();

return {
success: true,
redirectTo: "/login",
};
},
onError: async (error) => {
console.error(error);
return { error };
},
export const authProvider: AuthBindings = {
login: async ({ email: username, password, remember }) => {
try {
const result = await dataProvider.create({
resource: 'auth/login',
variables: {
username,
password,
},
meta: { noAuth: true },
});
console.warn(`authProvider login result`, result);
const { data: { access_token, admin } } = result;
setCookieIdentity({ access_token, admin });
return {
success: true,
redirectTo: "/",
};
} catch (error) {
console.warn(`authProvider login error`, error)
return {
success: false,
error: error as Error,
};
}

},
logout: async () => {
removeCookieIdentity();

return {
success: true,
redirectTo: "/login",
};
},
onError: async (error) => {
console.error(error);
return { error };
},
16 replies
RRefine
Created by stormy-gold on 3/17/2023 in #ask-any-question
query data cannot be undefined
import type { AuthBindings } from "@refinedev/core";
import * as cookie from "cookie";
import Cookies from "js-cookie";
import { promiseTimeout } from '@arijs/frontend/isomorphic/utils/promise'
import dataProvider from "./dataProvider";

const COOKIE_NAME = "user";

export interface UserIdentity {
access_token: string
admin: Record<string, any>
}

const setCookieIdentity = (user: UserIdentity) => {
Cookies.set(COOKIE_NAME, JSON.stringify(user));
}

const getCookieIdentity = (): UserIdentity | undefined => {
const parsedCookie = Cookies.get(COOKIE_NAME);
return parsedCookie ? JSON.parse(parsedCookie) : undefined;
}

const removeCookieIdentity = () => {
Cookies.remove(COOKIE_NAME);
}
// continues
import type { AuthBindings } from "@refinedev/core";
import * as cookie from "cookie";
import Cookies from "js-cookie";
import { promiseTimeout } from '@arijs/frontend/isomorphic/utils/promise'
import dataProvider from "./dataProvider";

const COOKIE_NAME = "user";

export interface UserIdentity {
access_token: string
admin: Record<string, any>
}

const setCookieIdentity = (user: UserIdentity) => {
Cookies.set(COOKIE_NAME, JSON.stringify(user));
}

const getCookieIdentity = (): UserIdentity | undefined => {
const parsedCookie = Cookies.get(COOKIE_NAME);
return parsedCookie ? JSON.parse(parsedCookie) : undefined;
}

const removeCookieIdentity = () => {
Cookies.remove(COOKIE_NAME);
}
// continues
16 replies
RRefine
Created by unwilling-turquoise on 3/17/2023 in #ask-any-question
query data cannot be undefined
I'll paste it here
16 replies
RRefine
Created by unwilling-turquoise on 3/17/2023 in #ask-any-question
query data cannot be undefined
maybe it's something on my auth provider, I used the client side cookies example (I saw the docs page with this code but I'm not finding it right now) I modified it slightly to call my data provider to actually login
16 replies