How do I use the token generated by the Google auth?
I am using Refine with built in Google authorization process. I would like to use the token, because I see that in the "utils" folder there is the json parser. How can I use that token for access purposes, authenticate users and let them use some routes or use the token? I am using MongoDB as my database.
5 Replies
Hi @ging_freecs. 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. However, I can provide you with some guidance on using Google authentication with Refine. You can follow the example provided in the Google Auth documentation (https://refine.dev/docs/examples/auth-provider/google-auth) to set up Google Login for your Refine project.
As for using the token for access purposes and authenticating users, you can refer to the AuthProvider documentation (https://refine.dev/docs/api-reference/core/providers/auth-provider) and the Understanding AuthProvider tutorial (https://refine.dev/docs/tutorial/understanding-authprovider/index) to create a custom authentication provider that suits your needs.
Unfortunately, I don't have any specific information on using MongoDB with Refine in the provided extracts.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------Google Auth | refine
You can use Google Login to control access and provide identity for your app. This example will guide you through how to connect Google Login into your project using refine.
Auth Provider | refine
Auth provider is an object that contains methods to handle authentication and access control in your app by having refine consume them. These methods expect to return a promise, so they can be used with async methods.
1. Auth Provider | refine
What is auth provider?
<@296624290843983873> kapa.ai is still learning and improving, please let us how it did by reacting below
like-gold•16mo ago
Hey @ging_freecs,
In the example, a simple
check
is used to check if there is a token in the local storage or not. If there is a token, the user is logged in. If not, the user is redirected to the login page.
You can see the code here: https://github.com/refinedev/refine/blob/next/examples/auth-google-login/src/App.tsx#L94-L112
However, in the real world, you should check the token with your backend. Refer to the google docs for more information: https://developers.google.com/identity/gsi/web/guides/verify-google-id-token
After you check
implementation in your authProvider
, you can use the useIsAuthenticated
hook and <Authenticated>
component to check if the user is authenticated or not.extended-salmon•16mo ago
Thank you very much! This is helpful