Unable to use social login with Auth0

I am trying to integrate social login specifically Google, microsoft, Apple along with passwordless email login into my react native expo application. I created the Auth0 app on Auth0 dashboard and copied over my domain and client id into my web3auth expo app. When I click google on social login page i get the following errors:

app interface the “page does not exist” and in my app console i see:
LOG Login status: undefined
ERROR Login failed with error: Invalid value provided to SecureStore. Values must be strings; consider JSON-encoding your values if they are serializable.

import React from "react";
import { Dimensions, ScrollView, StyleSheet, Text, View, TextInput } from "react-native";
import Constants, { AppOwnership } from "expo-constants";
import * as Linking from "expo-linking";
import "react-native-get-random-values";
import '@ethersproject/shims';
import "../globals";
// import * as WebBrowser from "@toruslabs/react-native-web-browser";
import * as WebBrowser from "expo-web-browser";
import * as SecureStore from "expo-secure-store";
// import EncryptedStorage from 'react-native-encrypted-storage';
import Web3Auth, { OPENLOGIN_NETWORK, LOGIN_PROVIDER, ChainNamespace } from "@web3auth/react-native-sdk";
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider';
import { ethers } from 'ethers';

const scheme = "userapp";
const redirectUrl =
//@ts-ignore
  Constants.appOwnership == AppOwnership.Expo || Constants.appOwnership == AppOwnership.Guest
    ? Linking.createURL("openlogin", {})
    : Linking.createURL("openlogin", { scheme: `${scheme}` });


// Dashboard Registration
const clientId = 'myWeb3AuthClientId';

// SDK Initialization
const chainConfig = {
  chainNamespace: ChainNamespace.EIP155,
  chainId: '0xaa36a7',
  rpcTarget: 'https://rpc.ankr.com/eth_sepolia',
  displayName: 'Ethereum Sepolia Testnet',
  blockExplorerUrl: 'https://sepolia.etherscan.io',
  ticker: 'ETH',
  tickerName: 'Ethereum',
  decimals: 18,
  logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png',
};

const ethereumPrivateKeyProvider = new EthereumPrivateKeyProvider({
  config: {
    chainConfig,
  },
});

// Create a global web3auth instance
let web3auth: Web3Auth | null = null;

// Function to initialize Web3Auth
async function initializeWeb3Auth() {
  if (!web3auth) {

    web3auth = new Web3Auth(WebBrowser, SecureStore, {
      clientId,
      network: OPENLOGIN_NETWORK.SAPPHIRE_DEVNET, // or other networks
      redirectUrl,
      useCoreKitKey: true,
      loginConfig: {
        jwt: {
          verifier: "falconstar-userapp-google",
          typeOfLogin: "jwt",
          clientId: "myAuth0ClientId",
        },
      },
    });

    await web3auth.init();

    if (web3auth.ready) {
      console.log("Web3Auth initialized successfully");
    } else {
      console.error("Web3Auth failed to initialize");
    }
  }
}

// Call the initialization function at app startup
initializeWeb3Auth();

// Function to handle login with different providers or email
export async function loginWithProvider(provider: string, email?: string): Promise<void> {
  if (!web3auth) {
    throw new Error("Web3Auth not initialized");
  }

  try {
    console.log(`Attempting login with provider: ${provider}`);

    const loginOptions: any = { loginProvider: provider };

    if (provider === 'email_passwordless' && email) {
      loginOptions.extraParams = { login_hint: email };
    }

    // Trigger the login process
    // const loginResponse = await web3auth.login(loginOptions);

    const loginResponse = await web3auth.login({
      loginProvider: LOGIN_PROVIDER.JWT,
      mfaLevel: "none",
      extraLoginOptions: {
        domain: "https://dev-myAuth0DomainAddress.eu.auth0.com",
        verifierIdField: "sub",
      },
    });

    // Optionally, handle the login response as needed
    console.log("Login status:", loginResponse);

    // Save login details securely on the device
    await SecureStore.setItemAsync("user", JSON.stringify(loginResponse));
  } catch (error: any) {
    console.error("Login failed with error:", error.message);
    console.error("Error details:", error);
    throw new Error("Login failed, please try again.");
  }
}

// Function to retrieve user details from SecureStore
export async function getUser(): Promise<string | null> {
  try {
    return await SecureStore.getItemAsync("user");
  } catch (error) {
    console.error("Failed to retrieve user data:", error);
    throw new Error("Failed to retrieve user data.");
  }
}

// Function to handle logout
export async function logout(): Promise<void> {
  try {
    if (!web3auth) {
      throw new Error("Web3Auth not initialized");
    }
    
    await web3auth.logout();
    await SecureStore.deleteItemAsync('user');
  } catch (error) {
    console.error('Logout failed', error);
    throw new Error('Logout failed, please try again.');
  }
}

// Function to handle email login
export async function loginWithEmail(email: string): Promise<void> {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  if (emailRegex.test(email)) {
    await loginWithProvider('email_passwordless', email);
  } else {
    throw new Error("Invalid email format");
  }
}

Hi Rameez,

Thank you for providing such detailed information. It looks like you’re facing an issue with the social login integration using Auth0 in your React Native Expo app. Below is a summary of your setup and the issues you’re encountering, which will help our support team address your query more efficiently.

Summary of Your Setup

  • SDK: Web3Auth Plug n Play
  • Platform: React Native Expo
  • Issue: Unable to use social login (specifically Google) with Auth0
  • Error Messages:
    • App interface shows “page does not exist”
    • Console logs:
      LOG Login status: undefined
      ERROR Login failed with error: Invalid value provided to SecureStore. Values must be strings; consider JSON-encoding your values if they are serializable.
      

Relevant Code Snippets

Your provided code includes the initialization and login logic for Web3Auth. Here are the key points:

  1. Initialization:

    const clientId = 'myWeb3AuthClientId';
    ...
    async function initializeWeb3Auth() {
      if (!web3auth) {
        web3auth = new Web3Auth(WebBrowser, SecureStore, {
          clientId,
          network: OPENLOGIN_NETWORK.SAPPHIRE_DEVNET,
          redirectUrl,
          useCoreKitKey: true,
          loginConfig: {
            jwt: {
              verifier: "falconstar-userapp-google",
              typeOfLogin: "jwt",
              clientId: "myAuth0ClientId",
            },
          },
        });
        await web3auth.init();
      }
    }
    
  2. Login:

    export async function loginWithProvider(provider: string, email?: string): Promise<void> {
      ...
      const loginResponse = await web3auth.login({
        loginProvider: LOGIN_PROVIDER.JWT,
        ...
        extraLoginOptions: {
          domain: "https://dev-myAuth0DomainAddress.eu.auth0.com",
          verifierIdField: "sub",
        },
      });
      await SecureStore.setItemAsync("user", JSON.stringify(loginResponse));
    }
    

Additional Information Needed

To further investigate this issue, could you please provide:

  1. Verifier Details:
    • Verifier Name: falconstar-userapp-google
    • JWKS Endpoint
    • Sample idToken (JWT)
  2. Verification:
    • Can you confirm if the redirectUrl is correctly set and matches the one configured in your Auth0 dashboard?
  3. Console Logs:
    • Browser Console Screenshots for any additional errors

This response was generated by an AI bot, and a person from the Web3Auth team will review your query and provide a more detailed answer. The response might be incorrect or incomplete, so please do not panic.

We’re here to help you get this resolved as quickly as possible!

Best regards,
[Your AI Assistant]

I am not usre where can i get
JWKS Endpoint or Sample IdToken

The allowed redirectUrl in my Autho dashboards are:

Web3Auth,
userapp://openlogin

so i changed the redirectURL from “openlogin” to ‘home’ now i don’t see the “page does not exist” and am redirected to my home page. however the home page is empty as i still get the following error on my react native console
LOG Login status: undefined
The home page is suppsoe to fill details like my public ethereum address, balance if any etc

As I see from the error, your code is breaking at this point

await SecureStore.setItemAsync("user", JSON.stringify(loginResponse));

I’m unsure why you are storing this detail. You can easily get that from web3auth from the getUserInfo function.

Your redirectUrl needs to be the same you used within the application while deeplinking. Please check this documentation for that: Installing PnP React Native SDK | Documentation | Web3Auth

Hi @yashovardhan , the full code snippet from my origional post has a consople log before i try to store login response:

 const loginResponse = await web3auth.login({
      loginProvider: LOGIN_PROVIDER.JWT,
      mfaLevel: "none",
      extraLoginOptions: {
        domain: "https://dev-myAuth0DomainAddress.eu.auth0.com",
        verifierIdField: "sub",
      },
    });

    // Optionally, handle the login response as needed
    console.log("Login status:", loginResponse);

    // Save login details securely on the device
    await SecureStore.setItemAsync("user", JSON.stringify(loginResponse));

I always get Login status as undefined, as far as i can tell login is not working for me.

Please change “openlogin” to “web3auth” and test

Hi @yashovardhan ,
yes that worked, quick question would you recommend storing web3auth.userinfo() response or web3auth.privKey in secure storage of the device i.e. i am think this information will be used until the user logs out ?

regards
Rameez

You do not need to store anything. It won’t be safe for you to mange that. Web3Auth does that internally. As long as the session exists, web3auth will rehydrate itself and do it. You just need to init in the constructor and check if the web3auth instance is connected.

1 Like

I changed the redirecturl to

`const scheme = "com.falconstar.userapp";
const redirectUrl =
//@ts-ignore
  Constants.appOwnership == AppOwnership.Expo || Constants.appOwnership == AppOwnership.Guest
    ? Linking.createURL("web3auth", {})
    : Linking.createURL("web3auth", { scheme: `${scheme}` })

now i get “page does not exist again”, this was working when I was using home:

const redirectUrl =
//@ts-ignore
  Constants.appOwnership == AppOwnership.Expo || Constants.appOwnership == AppOwnership.Guest
    ? Linking.createURL("home", {})
    : Linking.createURL("home", { scheme: `${scheme}` })

does the redirect url need to exist as a page / screen in my app ?

Yes do you need to have this on the web3auth route. The SDK creates this route to listen for the redirect.

sorry i didnt quite understand the last answer, Do i need to explicitly create the redirect route i.e. web3Auth? or does the sdk automatically creates it in my app ?

No web3auth creates it for you. You earlier mentioned it worked after changing “openlogin” to “web3auth”

Hi @yashovardhan ,
yes that worked, quick question would you recommend storing web3auth.userinfo() response or web3auth.privKey in secure storage of the device i.e. i am think this information will be used until the user logs out ?

hi @yashovardhan ,

it worked when i changed it to “home” which is a page that exists.
It doesn’t work when i change redirect URL to either “openlogin” or “web3auth” which I have not explicitly created.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.