Protected routes in next js - reactjs

I have two types of user . when user login i need to redirect them based on their role . Also protect routes. Only login user can go to specific routes based on their role. how this can be done in next js

You can get the auth token and create a serverSideProps https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props to redirect the user by role.

when the user logs into your app, you can save his permission in cookies and then get his permission via serverSideProps, and render the page according to the user.

Related

How to manage multiple role in React JS APP?

If I store the logged in user role in localstorage (i.e. user). So user will only see the user's dashboard. But if logged in user manully change the role in localstorage to admin. Then user now can see the content of admin dashboard. I just want to know how to fix this.
I hope these steps can help you
you can store the user role in the app (ContextApi or Redux).
and keep the token in the local storage.
when you reload the app you can use the useEffect hook to send a request to the backend to know what is the user's role.
and then edit the stored data.
and when you add any component to your app you can access what the user type can see this component and render it just for the suitable users.
you can take a look in this article

How to redirect to different pages in react app based in the user login credentials? like there is same page for all the user and

redirect the user to different pages based on the username id creadential. like first we will check the first letter of username input and figure out the type of user they are and then check in the respective database table for authentication and then redirect them to page according to the type of user they are . IN REACT NATIVE
I. Just make auth functions somewhere like in utils. Generally the logic you required for redirection perpose.
II. Then you can use the Apploading component which gets rendered before the Login Screen. When user starts the app if the credentials are saved call auth functions which redirects the user related screen or screens.
else: redirect to auth screen and after getting the credentials save them and call auth functions from there.
hope this helps. You have structure your navigation components.

redirection after signin with the use of cognito user groups

I have setup a cognito user pool with amplify and react. I now want to configure the authentication in such a way that after signin the users are redirected to pages depending on which group they are in meaning if someone from the group "admin" signsin he will be directed to a different page than someone from the group "user". Help would be very much appreciated.
Thanks alot.
Once you get the user accessToken after logging in via Amplify Auth, you will be able to get the groups user is assigned to via accessToken.payload["cognito:groups"].
You can also get the user session via const session = await Auth.currentSession();, inside you will find the accessToken.
Based on that you will be able to redirect wherever you need.

AAD implementation reply url

I am trying to integrate my application with AAD authentication but the replyurls which i am configuring in the AAD application is
https://www.example1.com/abc/account/login.aspx
but when i am coming back after authentication i am getting redirected to
https://www.example1.com/
Only and my request is coming as authenticated but i want user to redirect to full url which i have configured.
I have tried sending RedirectUri at the time of app configuration in startup class as same as https://www.example1.com/abc/account/login.aspx that time user is redirect to this url but that time request is not getting authenticated
any one knows how i will achieve this?
thank you in advance.
Reply URL is where the token would send to . It means that it is a endpoint
which signs in users for that provider. But after signing in, the user will be redirect to the Homepage(Sign-on) URL.
For your scenario, you can change the Home page (Sign-on)URL in both AAD Application and your APP config file to the URL which you want to use.
Please refer to this documentation for detailed instructions on how to set up these configurations. Like Wayne said, you need to make sure that the home page URL is matched to whatever site you want the users to be redirected to after login. Then make sure that the reply URL and the RedirectURI are matching.

Dynamic logout and login path for fosuserbundle

I have an application built in symfony 2.3 and FOSUserBundle for authenticating its users.
This application serves multiple users based on urls, pages looks like this /urlidentifier/login. This urlidentifier is a variable and it look for a [0-9A-Za-z] + to fill that slot.
FOSUserBundle config params like Login check path and logout path are saved and cached to a file (Symfony frozen parameter).For a single website user are easily authenticated with prefixing the FOSUserBundle parameters as well as Routing.
The real issue occur when the user are switch through multiple url (super privileges)
Scenario
When a super admin is logged and authenticated via urlidentifier1/login. He could switch himself to another website without logging out. Now the url changes from urlidentifier1/index to urlidentifier2/index, he would be logged in, But when he tries to logout, The parameters like logout path would be urlidentifier1/logout. When logout is triggered we will get an error like
"You must configure the logout path to be handled by the firewall using form_login in your security firewall configuration...”
How can I make the backend use such dynamic URLs?

Resources