Multiple authentication prompts with promptAsync().

Please provide the following:

  1. SDK Version: 38.0.8
  2. Platforms(Android/iOS/web/all): All

Hi there! I am new here and to Expo/RN. I’m trying to implement some basic authentication in my app with Azure ad. Right now I have a log in button that is displayed displayed on the WelcomeScreen, however when a user presses it and logs in (via AzureAd prompt), it takes them back to the Welcomescreen until they login again. Its like state isn’t being update or re-evaluated after they login. Am I missing something obvious with promptAsync?

App.js

export default function App() {

  const [user, setUser] = useState(null);

  WebBrowser.maybeCompleteAuthSession();

  const discovery = useAutoDiscovery(

    "placeholder"

  );

  // Request

  const [request, response, promptAsync] = useAuthRequest(

    {

      clientId: "placeholder",

      scopes: ["openid", "profile", "email", "offline_access"],

      // For usage in managed apps using the proxy

      redirectUri: makeRedirectUri({

        // For usage in bare and standalone

        native: "placeholder",

      }),

      responseType: ResponseType.Token,

    },

    discovery

  );

  const handleLogin = async () => {

    await promptAsync();

    if (response && response.type === "success") {

      var userDecoded = jwtDecode(response.params.access_token);

      setUser({

        accessToken: response.params.access_token,

        userDetails: userDecoded,

      });

    }

  };

  return (

    <AuthContext.Provider value={{ user, handleLogin }}>

      <NavigationContainer theme={navigationTheme}>

        {user ? <AppNavigator /> : <AuthNavigator />}

      </NavigationContainer>

    </AuthContext.Provider>

  );

}

(Where login button is)
WelcomeScreen.js

function WelcomeScreen({ navigation }) {
  const authContext = useContext(AuthContext);
  return (
    <ImageBackground
      style={styles.background}
      source={require("../assets/background.jpg")}
      blurRadius={4}
    >
      <View style={styles.logoContainer}>
        <Image source={require("../assets/Logo.png")} />
        <Text style={styles.titleText}>ITS Inventory</Text>
      </View>
      <View style={styles.buttonsContainer}>
        <AppButton
          title={"Login Via Azure"}
          style={styles.loginButton}
          onPress={() => authContext.handleLogin()}
        ></AppButton>
      </View>
    </ImageBackground>
  );
}

Thanks!!

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