Connecting Microsoft azure AD users on login to Supabase

Hi fellow devs,

I’m planning on creating an auth0 app, the users are supposed to log in with their Microsoft Azure AD. I am using Auth0 to login, and I would use Supabase to store users and additional data. Furthermore, I have been trying to figure out how I can have a user get automatically listed in my Supabase user list when they log in with Microsoft Azure AD over Auth0.

We’ve made a custom db connection to Supabase, but when I sign in with a social login, the user doesn’t automatically show up in the Supabase db, they will only show up in the Auth0 user list.

Any help to this would be appreciated!

You can try this. It’s worked for me. Function supabase.auth.signInWithOAuth doesn’t open URL, just get back the object, so you need to take URL from the object and click on it. Rest of code takes a token extract email from it and prints it on the screen, you can change it based on your needs.

import { StatusBar } from “expo-status-bar”;
import { Button, StyleSheet, Text, View } from “react-native”;
import { supabase } from “./lib/supabase”;
import { setupURLPolyfill } from “react-native-url-polyfill”;
import “react-native-url-polyfill/auto”;
import React, { useState, useEffect } from “react”;
import jwtDecode from “jwt-decode”;
import { Linking } from “react-native”;
import * as AuthSession from ‘expo-auth-session’;
import * as Random from ‘expo-random’;
var email;
setupURLPolyfill();

export default function App() {
const [accessToken, setAccessToken] = useState(“”);
const [error, setError] = useState(null);

const loginWithAzure = async () => {
try {
const { data, error } = await supabase.auth.signInWithOAuth({
provider: “azure”,
options: {
scopes: “email”
},
});

  if (error) {
    console.log("Error signing in with Azure:", error);
    setError(error);
  } else {
    console.log("Logged in with Azure:", data);

    // Open the authentication URL in a browser
    const url = data.url;
    const supported = await Linking.canOpenURL(url);
    if (supported) {
      await Linking.openURL(url);

      // Listen for URL changes
      Linking.addEventListener("url", handleURLChange);
    } else {
      console.log("Don't know how to open URI: " + url);
    }
  }
} catch (error) {
  console.log("Login error:", error);
  setError(error);
}

};

const handleURLChange = async (event) => {

// Get the URL from the event object
const url = event.url;

// Check if the URL starts with the redirect URI
const redirectURI = AuthSession.makeRedirectUri();
  
if (url.startsWith(redirectURI)) {
  // Remove the listener to prevent multiple calls
   //Linking.removeEventListener("url");
    Linking.removeAllListeners("url")
    
  // Parse the URL and get the access token
  const queryParams = new URLSearchParams(url.split("#")[1]);
  
  const accessToken = queryParams.get("access_token");
  const decodedToken = jwtDecode(accessToken);
   email = decodedToken.email;
  // Update state with access token
  setAccessToken(accessToken);
    
  // Set the access token as a header for Supabase requests
 
  supabase.auth.setSession(accessToken)
}

};

return (


{error ? (
<Text style={[styles.text, styles.error]}>
Error: {error.message || “An unknown error occurred.”}

) : null}
{accessToken ? (
User Email: {email}
) : null}

);
}```