firebase / firebaseui-web

FirebaseUI is an open-source JavaScript library for Web that provides simple, customizable UI bindings on top of Firebase SDKs to eliminate boilerplate code and promote best practices.
https://firebase.google.com/
Apache License 2.0
4.58k stars 1.06k forks source link

signInSuccessUrl always required #3

Closed MarcMouallem closed 8 years ago

MarcMouallem commented 8 years ago

The documentation states that the signInSuccessUrl is only required as follows.

signInSuccessUrl: The URL where to redirect the user after a successful sign-in. Required when the signInSuccess callback is not used or when it returns true.

However this is not the case. Currently by having the signInSuccess callback return false you can ignore the signInSuccessUrl, but it it still required otherwise the following error will be thrown and the signInSuccess function will not be called.

firebase-auth.js:48 Uncaught Error: Configuration signInSuccessUrl is required.

bojeil-google commented 8 years ago

signInSuccessUrl is currently always required even when false is returned in the callback.

ghost commented 8 years ago

Please make "signInSuccessUrl" optional. If it's set, do the redirect, if not - do nothing. This leads to some strange behaviour. I use firebase for authentication on my server and when I want to access the id_token (it's fetched async via user.getToken()), in the meantime - while I'm waiting for the token - the redirect occurs.

bojeil-google commented 8 years ago

We will work on making that optional. However for you case, return false in your sign in callback so no redirect happens while you call user.getToken() or on resolution, do the redirect manually.

alexkreidler commented 8 years ago

I have the same issue. I hope it's fixed soon.

bojeil-google commented 8 years ago

Just to clarify, the callback I was referring to is explained in the README.md in the "Example with all parameters used": 'callbacks': { 'signInSuccess': function(currentUser, credential, redirectUrl) { // No redirect. return false; } }

itispeach commented 8 years ago

@bojeil-google could you expound a little for me. I'm extremely new to code and am having trouble redirecting manually. Here's what I tried. Any help would be greatly appreciated.

'callbacks': { 'signInSuccess': function(currentUser, credential, redirectUrl) { var user = currentUser; // var authenticated_URL = redirectUrl; if (user != null){ return true; authenticated_URL = 'https://google.com'; // authenticated_URL = '<my-website's-protected-page>; } else { return false; } } }

bojeil-google commented 8 years ago

Hey @itispeach, the redirectUrl parameter is optional and will only be populate if you pass a signInSuccessUrl query parameter in the sign in widget url. I assume you are not passing. In addition signInSuccess callback will be triggered only when a user is logged in. So currentUser should always be populated. Here is one way you can do this:

'signInSuccessUrl': '<url-to-redirect-to-on-success>', 'callbacks': { 'signInSuccess': function(currentUser, credential, redirectUrl) { // This will redirect to redirectUrl if available or the signInSuccessUrl you specified in the config when // there is no redirectUrl. // return true; // If you to redirect manually, redirect here and return false. window.location.href = '<my-website's-protected-page>'; return false; } }

itispeach commented 8 years ago

Hmmm, I'm still stuck. here's more of my code. I tried to apply your example, but I can still navigate strait to the "protected page" even though I'm in an incognito window. I must be missing a concept, here.

`

<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>

<script type="text/javascript">
  var uiConfig = {
      'queryParameterForWidgetMode': 'mode',
      'queryParameterForSignInSuccessUrl': 'signInSuccessUrl',
      'signInSuccessUrl': '<private-site-that-only-authenticated-users-can-visit>',
      'signInOptions': [
        firebase.auth.EmailAuthProvider.PROVIDER_ID
      ],
      'callbacks': {
        'signInSuccess': function(currentUser, credential, redirectUrl) {
          window.location.href = '<public-site-its-okay-to-visit>';
          return false;
        }
      }
    };
  </script>`

Do I need to use this somewhere? firebase.auth().onAuthStateChanged(function(user) {});

bojeil-google commented 8 years ago

Hey @itispeach, check the response I gave on stackoverflow: http://stackoverflow.com/questions/38191852/is-there-a-signinfailureurl-parameter-for-github-project-firebaseui-for-web

TMSCH commented 8 years ago

We fixed this issue in the new release. It will raise an error only if there is the signInSuccessUrl is required, i.e. if the signInSuccess callback returns true (i.e. proceed with redirect) and no redirectUrl has been given as a URL parameter, or that both signInSuccessUrl and signInSuccess callback are not given.

oliversisson commented 7 years ago

I thought I'd just write the solution to this error "No redirect URL has been found. You must either specify a signInSuccessUrl in the configuration, pass in a redirect URL to the widget URL, or return false from the callback"

All you need to do is return false in the signInSuccess callback

  const uiConfig = {
    callbacks: {
      signInSuccess: () => false,
    },
GF-Huang commented 5 years ago

@oliversisson Not work.

image

bojeil-google commented 5 years ago

Your callback is returning a promise which evaluates to true.

GF-Huang commented 5 years ago

@bojeil-google Oh, thanks, solved.

brandonfajardo commented 5 years ago
Screen Shot 2019-06-12 at 5 07 55 PM Screen Shot 2019-06-12 at 5 07 09 PM

Still receiving this error, please help! @bojeil-google

bojeil-google commented 5 years ago

You are returning a promise which resolves to true which triggers the redirect. Since no URL provided, an error is shown. Change the callback to be synchronous.

brandonfajardo commented 5 years ago

You are returning a promise which resolves to true which triggers the redirect. Since no URL provided, an error is shown. Change the callback to be synchronous.

@bojeil-google Is it possible to use async here?

alipetarian commented 4 years ago

@brandonfajardo I used this way and it worked for me.

image

Chuiantw1212 commented 3 years ago

Why is this issue closed? Having a not so making sense work around did not really solve the problem. In modern framework, it is a common scenario to route to various paths after signed in.

It is logical to make this field optional, considering making it optional won't make a breaking change.