plain-purple
plain-purple9mo ago

Refine OAuth doesn't work to send user to "admin" page after login

I tried OAuth (with Discord) and when the user signs in, they aren't sent to the "admin" page.
5 Replies
kapa.ai
kapa.ai9mo ago
Hi @curzon5298. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The extracts provided do not contain specific information about implementing OAuth with Discord and redirecting to the "admin" page after sign in. However, in general, you can use the useLogin hook to trigger the login process and specify a redirectPath. Then, handle this URL in your login method of the authProvider. Here's an example:
import { useLogin } from "@pankod/refine";

const { mutate: login } = useLogin();

login({ redirectPath: "/admin" });
import { useLogin } from "@pankod/refine";

const { mutate: login } = useLogin();

login({ redirectPath: "/admin" });
And in your authProvider:
import type { AuthBindings } from "@pankod/refine";

const authProvider: AuthBindings = {
login: async ({ redirectPath }) => {
// Perform login operation here
// If login is successful:
return {
success: true,
redirectTo: redirectPath,
};
},
// other methods...
};
import type { AuthBindings } from "@pankod/refine";

const authProvider: AuthBindings = {
login: async ({ redirectPath }) => {
// Perform login operation here
// If login is successful:
return {
success: true,
redirectTo: redirectPath,
};
},
// other methods...
};
For more detailed instructions and code examples, you can refer to the refine documentation (https://refine.dev/docs). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@592756480118358016> kapa.ai is still learning and improving, please let us know how it did by reacting below
plain-purple
plain-purple9mo ago
@kapa.ai
check: async (ctx) => {
const { token } = nookies.get(ctx);
const { data } = await supabaseClient.auth.getUser(token);
const { user } = data;

if (user) {
return {
authenticated: true,
};
}

return {
authenticated: false,
redirectTo: "/login",
};
},
check: async (ctx) => {
const { token } = nookies.get(ctx);
const { data } = await supabaseClient.auth.getUser(token);
const { user } = data;

if (user) {
return {
authenticated: true,
};
}

return {
authenticated: false,
redirectTo: "/login",
};
},
This is what I did to check for auth using the Authprovider
kapa.ai
kapa.ai9mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Your check method in the authProvider seems to be correctly implemented. It checks if a user is authenticated by getting the user's token and using it to fetch the user's data from Supabase. If a user is found, it returns { authenticated: true }, otherwise, it returns { authenticated: false, redirectTo: "/login" }. Here's your code for reference:
check: async (ctx) => {
const { token } = nookies.get(ctx);
const { data } = await supabaseClient.auth.getUser(token);
const { user } = data;

if (user) {
return {
authenticated: true,
};
}

return {
authenticated: false,
redirectTo: "/login",
};
},
check: async (ctx) => {
const { token } = nookies.get(ctx);
const { data } = await supabaseClient.auth.getUser(token);
const { user } = data;

if (user) {
return {
authenticated: true,
};
}

return {
authenticated: false,
redirectTo: "/login",
};
},
This method is part of the authProvider object in refine, which is used to handle authentication and access control in your application. The check method specifically is used to check if a user is authenticated or not. If you're still having issues with users not being redirected to the "admin" page after signing in, it might be due to how you're handling the redirectTo property in your login method. Make sure you're returning a redirectTo property pointing to "/admin" upon successful login. For more information on how to use the authProvider in refine, you can refer to the refine documentation (https://refine.dev/docs/tutorial/understanding-authprovider/index/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@592756480118358016> kapa.ai is still learning and improving, please let us know how it did by reacting below