I am currently working on a calendar application which needs a login/user authentication. I tried doing it using azure, but due to my lack of expertise in Azure I found myself lost in multiple tutorials. I need the solution of this one. Any help or leads would be really helpful.
Here is how my application looks like.
Index.js
ReactDOM.render(
<React.StrictMode>
<ContextWrapper>
<App />
</ContextWrapper>
</React.StrictMode>,
document.getElementById("root")
);
App.js
return (
<Router>
<Routes>
<Route exact path="/" element = {
<React.Fragment>
<div className="overall">
<CalendarHeader />
<div className="main-content-area">
<Sidebar />
<Month month={currentMonth} />
<EventModal />
</div>
</div>
</React.Fragment>
}>
</Route>
<Route exact path="/addEvents" element={<UpdateEventsForms />}></Route>
<Route exact path="/editdeletedata" element={<EditAndDelete />}></Route>
<Route exact path="/adminPage" element={<AdminPage />}></Route>
</Routes>
</Router>
);
Header.js
<div>
<button className="button-calendar-today">Sign-In</button>
<button className="button-calendar-today" onClick={() => navigate("/adminPage")}>Admin
Login</button>
</div>
And how I want is like when the user is not logged-in then don’t want to display admin page instead I would like to show sign-in button. But when the user is logged-in I want to display the admin page not the sign-in button.
Moreover, when clicked on Admin login that will take the user to the Admin Page (<AdminPage />
) which is user in my react-router above in App.js
2
Answers
I did this, but getting this error. Please let me know what am I missing here?
I tried the following React.js code for login/user authentication with Azure Active Directory.
Code :
AdminPage.js :
Home.js :
SignInButton.js :
msalConfig.js :
App.js :
I added the output URL below in the Azure AD app’s Authentication as a Single-page application.
Output :
The React application below ran successfully.
I received the output below in the browser. Then, I clicked on Sign In and selected my credentials for signing in as shown below.
I successfully signed in and got the Admin Page as below.