helpful-purple
helpful-purple8mo ago

Multiple Auth Provider in a single app. Possible?

Hi everyone! A refine newbie here. First, a huge thanks to refine team for building something pretty useful & keeping it open source. It's commendable. I had a question about refine entry point (https://refine.dev/docs/api-reference/core/components/refine-config/). Is it possible to have two different routes under two different refine entry points. The reason, I ask is because I would like to use different auth providers for one specific route while rest of the routes would have a different auth provider. Given that auth providers go hand in hand with refine entry point, I am wondering if it's possible to have two entry points. If not, let me know if it's possible to have two auth providers. One of the auth provider is a Custom Auth Provider and other is Azure Active Directory. Only one route is protected by AAD and rest all routes would be protected by Custom Auth Provider. TIA.
4 Replies
kapa.ai
kapa.ai8mo ago
Hi @pankaj_81531. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hello and welcome to the refine community! We're glad to hear that you're finding refine useful. Regarding your question, refine does allow you to use multiple data providers in your app. However, the same functionality does not extend to auth providers. You can only pass one auth provider to the <Refine /> component. That being said, you could potentially create a custom auth provider that internally decides which auth method to use based on the route or some other parameter. This custom auth provider would essentially wrap your Custom Auth Provider and Azure Active Directory Auth Provider. Here's a simplified example of how you might structure this:
const customAuthProvider = {
// Your custom auth provider methods
};

const azureAuthProvider = {
// Your Azure AD auth provider methods
};

const authProvider = {
login: async (params) => {
if (params.route === 'azureRoute') {
return azureAuthProvider.login(params);
} else {
return customAuthProvider.login(params);
}
},
// Implement other methods in a similar way
};

<Refine authProvider={authProvider} />;
const customAuthProvider = {
// Your custom auth provider methods
};

const azureAuthProvider = {
// Your Azure AD auth provider methods
};

const authProvider = {
login: async (params) => {
if (params.route === 'azureRoute') {
return azureAuthProvider.login(params);
} else {
return customAuthProvider.login(params);
}
},
// Implement other methods in a similar way
};

<Refine authProvider={authProvider} />;
In this example, the login method of the authProvider checks the route and calls the corresponding method from either the customAuthProvider or the azureAuthProvider. You would need to implement the other methods (logout, check, etc.) in a similar way. Please note that this is a simplified example and you might need to adjust it based on your specific requirements and the APIs provided by your auth providers. For more information on auth providers in refine, you can refer to the authProvider documentation (https://refine.dev/docs/api-reference/core/providers/auth-provider/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8mo ago
<@1148728588506501242> kapa.ai is still learning and improving, please let us know how it did by reacting below
rival-black
rival-black8mo ago
Hello @pankaj_81531, currently multiple auth provider not possible but kapa.ai answers is great. is it works for you ?
helpful-purple
helpful-purple8mo ago
Hi @alicanerdurmaz - Thanks for checking. The answer looks good. We have not yet tried this but were able to design a solution. Once we implement, we would know better.