How to get user data like email, username etc usi...
# help-and-questions
p
Also what about new identity based auth?
I don't get user on sign in/up with google in database, it's bug??
so I need to check all out and maybe manually add user or do something using skipbrowserredirect as true
I am paid user, is there any faster way to get response?
sample code supabase.auth .signInWithOAuth({ provider: 'google', options: { skipBrowserRedirect: true, scopes: 'profile email', }, }) .then((response) => { // Function to call after successful authentication yourFunctionName(response.user); // Pass the user info or data to your function }) .catch((error) => { // Handle authentication error console.error(error); });
g
This is a user helping user forum, not guarantee of response time, or of any. The only direct communication is with support. skipbrowserredirect will not launch the Google login so nothing will happen, but you will get a URL of where it would have gone.
p
skipbrowserredirect will not launch the Google login, at all?
I think it'0s related to callback uri
not before sending
g
SignInWithOauth never returns any user data. It will redirect back to your app at siteUrl or your redirectTo and the createClient will run and get the session info.
p
any way to get user data?
and thank you
g
Only after it has redirect back to your app after the Google signIn screen. But that call will return, it just is normally you immediately leave your app to the Google signIn screen. When you come back it is to siteUrl or redirectTo url.
p
so this skipBrowserRedirect: false, scopes: 'profile email', }, }) .then((response) => { // Function to call after successful authentication yourFunctionName(response.user); ( skipBrowserRedirect: false,) will call function
the problem is some users are not added to database at all 😦
trying to get them, nothing...
g
.then() will never have anything useful (other than error). Are you getting a Google login screen? After you do that you can look in the dashboard as see if the user is created.
p
.then() will never have anything? but it's promises
g
It will never have a user session. Just the URL of the google login or error.
p
yes I got sign screen
so have ot get user session
g
After you signin, your app will start over.
p
that's bad
how to persist user?
g
The createClient handles that at app start. If the redirect to it has user token (like after google signin) it will sign the user in. You can then do await getSession to see if there is a user signed in and get their info.
p
let me try it... thank you
g
You should look at one of the guides to see the flow.
p
const supabase = createClient("YOUR_SUPABASE_URL", "YOUR_SUPABASE_KEY"); // At app start or whenever needed async function checkUserSession() { const { user, session } = await supabase.auth.getSession(); if (user && session) { // User is signed in // You can access user information using 'user' object console.log(user); // Call your function passing user information yourFunctionName(user); } else { // User is not signed in // Perform necessary actions } } // Call the function to check the user session checkUserSession();
that's ok?
g
That general flow looks right. session null means there will not be a user signin occurring. Using the await is needed because in some cases the user session needs to be refreshed first or after a signin as the token is converted to a session).
p
thank you so much!!!
I am write code and testing soon 😉
var noSession=false; // At app start or whenever needed async function checkUserSession() { console.log(checkUserSession); const { user, session } = await supabase.auth.getSession(); if (user && session) { console.log("user && session"); // User is signed in // You can access user information using 'user' object noSession=false; console.log(user); const oAuthToken = session.provider_token; // use to access provider API console.log(oAuthToken); // Call your function passing user information // yourFunctionName(user); } else { // User is not signed in // Perform necessary actions noSession=true; console.log("noSession"); } } async function UseGoogle() { if (!noSession) return; console.log("provider: 'google'"); const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { scopes: 'email' } }); if (data) { console.log("google data "+data); const oAuthToken = data.session.provider_token; // use to access provider API console.log(oAuthToken); } } // Call the function to check the user session checkUserSession();
doesnt give me session or anything on login
g
So the JS docs shows {data, error } = await getSession(). My code shows data.session and then data.session.user for the two useful objects returned in data.
p
I am doing session checking Refresh Session Example Refresh Session Example Refresh Session // Initialize Supabase client const supabaseUrl = 'YOUR_SUPABASE_URL'; const supabaseKey = 'YOUR_SUPABASE_KEY'; const supabase = createSupabaseClient(supabaseUrl, supabaseKey); // Function to refresh the user's session async function refreshSession() { try { const { error } = await supabase.auth.refreshSession(); if (error) { console.error('Failed to refresh session:', error.message); } else { console.log('Session refreshed successfully'); // Perform any additional actions after session refresh } } catch (error) { console.error('Error refreshing session:', error.message); } }
g
refreshSession won't work until you have a session. Which means waiting for getSession, then you don't need to refresh the session. What is createSupabaseClient?
Your code with getSession would not work as you used {session,user} = await getSession versus {data} = await getSession.
p
async function signInWithGoogle() { try { const { data, error } = await supabase.auth.signInWithOAuth( { provider: 'google', options: { queryParams: { access_type: 'offline', prompt: 'consent', scope: 'profile email phone address', // Add 'phone' to the scope }, }, }); console.log(data); // Use the data if it's not null console.log(error); // Handle the error if it exists } catch (error) { console.log(error); // Catch any additional errors } }
async function refreshSession() { try { const { data, error } = await supabase.auth.getSession() console.log(data); console.log("name: "+data.session.user.user_metadata.full_name); console.log("email: "+data.session.user.user_metadata.email); }catch (error) { console.log(error); // Catch any additional errors } }
thank you!