Commit b783673 1 parent 9ca6a79 commit b783673 Copy full SHA for b783673
File tree 9 files changed +74
-29
lines changed
9 files changed +74
-29
lines changed Original file line number Diff line number Diff line change
1
+ NEXT_PUBLIC_AZURE_AD_CLIENT_ID = bb626b2e-8bd8-44ee-bb90-afc1959a9274
2
+ NEXT_PUBLIC_AZURE_AD_TENANT_ID = 5e3f37f1-3b80-467a-a949-70b4cd2c4ac0
3
+ NEXT_PUBLIC_REDIRECT_URI = /auth
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const nextConfig = {
11
11
// Set this to true if you would like to use SVGR
12
12
// See: https://github.com/gregberge/svgr
13
13
svgr : false ,
14
+ // page dir
14
15
} ,
15
16
} ;
16
17
Original file line number Diff line number Diff line change 1
- import 'tailwindcss/tailwind.css' ;
2
1
import { AppProps } from 'next/app' ;
3
- import { MsalReactProvider } from '@myorg/msal-react' ;
2
+ import { MsalProviderComponent } from '@myorg/msal-react' ;
4
3
5
- function CustomApp ( { Component, pageProps } : AppProps ) {
4
+ function MyApp ( { Component, pageProps } : AppProps ) {
6
5
return (
7
- < MsalReactProvider >
8
- < Component { ...pageProps } /> ;
9
- </ MsalReactProvider >
10
- )
6
+ < MsalProviderComponent >
7
+ < Component { ...pageProps } />
8
+ </ MsalProviderComponent >
9
+ ) ;
11
10
}
12
11
13
- export default CustomApp ;
12
+ export default MyApp ;
Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
3
+ import { useEffect } from "react" ;
4
+ import { useMsal } from "@azure/msal-react" ;
5
+
6
+ export default function AuthPage ( ) {
7
+ const { instance } = useMsal ( ) ;
8
+
9
+ useEffect ( ( ) => {
10
+ const handleRedirectPromise = instance . handleRedirectPromise ( ) ;
11
+ handleRedirectPromise . catch ( ( error ) => {
12
+ console . error ( error ) ;
13
+ } ) ;
14
+ } , [ instance ] ) ;
15
+
16
+ return null ;
17
+ }
Original file line number Diff line number Diff line change 1
- import 'tailwindcss/tailwind.css' ;
1
+ 'use client'
2
2
3
- export const metadata = {
4
- title : 'Welcome to my-app' ,
5
- description : 'Generated by create-nx-workspace' ,
6
- } ;
3
+ import 'tailwindcss/tailwind.css' ;
4
+ import { MsalProviderComponent } from '@myorg/msal-react' ;
5
+ import { Metadata } from 'next'
6
+
7
+ // export const metadata: Metadata = {
8
+ // title: 'Home',
9
+ // description: 'Welcome to Next.js',
10
+ // }
7
11
8
12
export default function RootLayout ( {
9
13
children,
@@ -12,7 +16,14 @@ export default function RootLayout({
12
16
} ) {
13
17
return (
14
18
< html lang = "en" >
15
- < body > { children } </ body >
19
+ < body >
20
+ < MsalProviderComponent >
21
+ < div id = "layout-children" >
22
+ { children }
23
+ </ div >
24
+ </ MsalProviderComponent >
25
+ </ body >
16
26
</ html >
27
+
17
28
) ;
18
- }
29
+ }
Original file line number Diff line number Diff line change 1
1
'use client'
2
+
2
3
import React from 'react' ;
3
4
import { ButtonLogin , ButtonLogout } from '@myorg/msal-react' ;
5
+ import { AuthenticatedTemplate , UnauthenticatedTemplate } from '@azure/msal-react' ;
4
6
5
7
export default function Page ( ) {
6
8
return (
7
9
< div >
8
- < div className = "bg-gray-50 " >
10
+ < div className = "bg-slate-900 h-screen w-screen " >
9
11
< div className = "max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:py-16 lg:px-8 lg:flex lg:items-center lg:justify-between" >
10
- < h2 className = "text-3xl font-extrabold tracking-tight text-gray-900 sm:text-4xl" >
12
+ < h2 className = "text-3xl font-extrabold tracking-tight text-neutral-300 sm:text-4xl" >
11
13
< span className = "block" > Ready to dive in?</ span >
12
14
< span className = "block text-indigo-600" >
13
15
Start your free trial today.
14
16
</ span >
15
17
</ h2 >
16
18
< div className = "mt-8 flex lg:mt-0 lg:flex-shrink-0" >
17
- < ButtonLogin />
18
- < ButtonLogout />
19
+ < AuthenticatedTemplate >
20
+ < ButtonLogout />
21
+ </ AuthenticatedTemplate >
22
+ { /* <UnauthenticatedTemplate> */ }
23
+ < ButtonLogin />
24
+ { /* </UnauthenticatedTemplate> */ }
19
25
</ div >
20
26
</ div >
21
27
</ div >
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { useMsal } from '@azure/msal-react' ;
3
- import { loginRequest } from '../msal-react' ;
4
3
5
4
export function ButtonLogin ( ) {
6
5
const { instance } = useMsal ( ) ;
7
6
7
+ const loginHandler = ( ) => {
8
+ instance . loginRedirect ( ) ;
9
+ } ;
10
+
8
11
return (
9
12
< div className = "inline-flex rounded-md shadow" >
10
13
< a
11
14
href = "#"
12
- onClick = { ( ) => instance . loginPopup ( loginRequest ) }
15
+ onClick = { loginHandler }
13
16
className = "inline-flex items-center justify-center px-5 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700"
14
17
>
15
18
Log In
Original file line number Diff line number Diff line change @@ -4,11 +4,15 @@ import { useMsal } from '@azure/msal-react';
4
4
export function ButtonLogout ( ) {
5
5
const { instance } = useMsal ( ) ;
6
6
7
+ const logoutHandler = ( ) => {
8
+ instance . logoutRedirect ( ) ;
9
+ } ;
10
+
7
11
return (
8
12
< div className = "ml-3 inline-flex rounded-md shadow" >
9
13
< a
10
14
href = "#"
11
- onClick = { ( ) => instance . logoutPopup ( ) }
15
+ onClick = { logoutHandler }
12
16
className = "inline-flex items-center justify-center px-5 py-3 border border-transparent text-base font-medium rounded-md text-indigo-600 bg-white hover:bg-indigo-50"
13
17
>
14
18
Logout
Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
1
3
import React from 'react' ;
2
4
import { Configuration , PublicClientApplication } from '@azure/msal-browser' ;
3
5
import { MsalProvider } from '@azure/msal-react' ;
@@ -18,12 +20,11 @@ const msalConfig: Configuration = {
18
20
// Initialize MSAL instance with your configuration
19
21
const msalInstance = new PublicClientApplication ( msalConfig ) ;
20
22
21
- // Provide a login request
22
- export const loginRequest = {
23
- scopes : [ "User.Read" ] ,
24
- } ;
25
-
26
23
// Create a component to provide MSAL functionalities
27
- export const MsalReactProvider : React . FC < { children : React . ReactNode } > = ( { children } ) => {
28
- return < MsalProvider instance = { msalInstance } > { children } </ MsalProvider > ;
24
+ export const MsalProviderComponent : React . FC < { children : React . ReactNode } > = ( { children } ) => {
25
+ return (
26
+ < div id = "msal-provider" >
27
+ < MsalProvider instance = { msalInstance } > { children } </ MsalProvider > ;
28
+ </ div >
29
+ )
29
30
} ;
You can’t perform that action at this time.
0 commit comments