How do I make Google SignIn's redirect URL Dynamic?

I’m using Google Sign In inside Login page.
And onClick of the Sign In button I’m executing this code :point_down:

{{navigateTo('https://abcde.supabase.co/auth/v1/authorize',{provider:"google",
redirect_to:`https://app.appsmith.com/app/feedback-app-dev/${auth.getUserDashboardAndId()}`},'SAME_WINDOW')}}

Here, the user should be redirected based on the user’s role.
This is my getUserDashboardAndId function

  getUserDashboardAndId: () => {
    //getUserData is the API call made to supabse, which returns some data.
    getUserData.run((user) => {
	storeValue('email', user.email)
    })
    getEmployeeByEmail.run((user) => {
       storeValue("loggedin_user", user[0]);
    });
    const role = appsmith.store.loggedin_user.role;
    if (role === "Employee") {
      return "employeedashboard-63d89abcb8b46679d190f4c8";
    } else if (role === "Reviewer") {
      return "reviewerdashboard-63e24e094fc63a0df6b867ae";
    } else {
      return "admindashboard-63d89abcb8b46679d190f4e5";
    }
  },

Error: On Signing In I’m getting TypeError: Cannot read properties of undefined (reading ‘role’)
Seems like the code is running first before login data gets stored inside Store.

redirect_to: https://app.appsmith.com/app/feedback-app-dev/${auth.getUserDashboardAndId()}
My only concern is to redirect this URL to the respective dashboards based on the user’s role.

Hey, here you are using async actions and expecting sync results. Check out this article - How do I use Async/Await in Javascript?

Also, keep in mind - storeValue is an async function

1 Like