flat-fuchsia
flat-fuchsia•17mo ago

How Can I get user email with Google Login AuthProvider

ℹ️ info I'm using Google Login as AuthProvider & Supabase as database I want to get user Email by a given user id There's no email field in my supabase's profiles table by default (as the pic) ❓ issue 1. So, I'm wondering, do I need to save email after user login? If I did this, I can get user email by useOne easily. If this is the right answer, can you give some reference to do this? 🙏‍ I saw there's onFinish property here (https://refine.dev/docs/api-reference/core/hooks/auth/useLogin/#usage), but it seems it's for normal login (account & password) But I'm using Google Login as AuthProvider. I got no idea how to do this 2. Is there's a hook like useGetIdentity to get user data? when I use useGetIdentity, I can get my own user data, including email even it isn't in database. It seems useGetIdentity can only get the current user data. Is there's a hook like useGetIdentity to get user data?
useLogin | refine
useLogin data hook from refine is a modified version of react-query's useMutation for authentication.
No description
8 Replies
eastern-cyan
eastern-cyan•17mo ago
There’s this hook (useGetIdentity) that calls getUserIdentity method of the authProvider. I think its best to use those to get user data 🤔 https://refine.dev/docs/api-reference/core/hooks/auth/useGetIdentity/
useGetIdentity | refine
useGetIdentity data hook from refine is a modified version of react-query's useQuery for retrieving user data
eastern-cyan
eastern-cyan•17mo ago
Guessing you get a jwt token after you login with the user and you can parse that jwt token to get some data from it
eastern-cyan
eastern-cyan•17mo ago
We have an example auth-google-login which has a jwt parse utility https://github.com/refinedev/refine/tree/next/examples/auth-google-login
GitHub
refine/examples/auth-google-login at next · refinedev/refine
Build your React-based CRUD applications, without constraints. - refine/examples/auth-google-login at next · refinedev/refine
eastern-cyan
eastern-cyan•17mo ago
Not the best implementation of getUserIdentity function but i think this will give you some ideas
flat-fuchsia
flat-fuchsia•17mo ago
Sorry for the late reply. After reading the doc I still can't understand how to use getUserIdentity and useGetIdentity together 🥲 Could you give me an example?
fair-rose
fair-rose•17mo ago
eastern-cyan
eastern-cyan•17mo ago
Sorry @劉哲宇, looks like we've misunderstood the question 🤦‍♂️ Guessing, you're using social login features of supabase and integrated with our authProvider 🤔 Let me share a supabase docs here about managing user data https://supabase.com/docs/guides/auth/managing-user-data Supabase does not expose their auth schema for security purposes and advises on using a public table like profiles, users etc. After that, it will be same like other public resources/tables and you will be able to access to it using useOne or other data hooks. Let me know if you have any issues 🙏
flat-fuchsia
flat-fuchsia•17mo ago
@aliemirs @salihozdemir Thanks for your help. I thought I find the answer . supabase had created users table and store lots of auth info (including, role, email, etc...) And I have to do some settings if I want to access users table https://supabase.com/docs/reference/javascript/admin-api and https://supabase.com/docs/reference/javascript/auth-admin-getuserbyid . by doing this, I can get a user data by user id 🎉
No description