-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1734 from DylanJG01/main
Keycloak Test Login test.
- Loading branch information
Showing
11 changed files
with
296 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useAuth } from 'react-oidc-context'; | ||
import SignInButton from './SignInButton'; | ||
import SignOutButton from './SignOutButton'; | ||
|
||
function LoginLogoutToggle({ classes, isMobile }) { | ||
const auth = useAuth(); | ||
|
||
if (auth?.isAuthenticated) { | ||
return <SignOutButton auth={auth} classes={classes} isMobile={isMobile} />; | ||
} | ||
return <SignInButton auth={auth} classes={classes} isMobile={isMobile} />; | ||
} | ||
|
||
export default LoginLogoutToggle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Button, Typography, Link } from '@mui/material'; | ||
|
||
function SignInButton({ auth, classes, isMobile }) { | ||
if (isMobile) { | ||
return ( | ||
<Link | ||
sx={{ | ||
textDecoration: 'none', | ||
color: ({ palette }) => palette.text.primary, | ||
}} | ||
onClick={auth.signinRedirect} | ||
> | ||
Sign in | ||
</Link> | ||
); | ||
} | ||
|
||
return ( | ||
<Button> | ||
<Link | ||
sx={{ | ||
textDecoration: 'none', | ||
'& :hover': { | ||
color: ({ palette }) => palette.text.primary, | ||
}, | ||
}} | ||
className={classes.buttonStyle} | ||
onClick={auth?.signinRedirect} | ||
> | ||
<Typography className={classes.buttonStyle}>Sign in</Typography> | ||
</Link> | ||
</Button> | ||
); | ||
} | ||
|
||
export default SignInButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Box, Button, Typography, Link, Avatar } from '@mui/material'; | ||
|
||
function SignOutButton({ auth, classes, isMobile }) { | ||
if (isMobile) { | ||
return ( | ||
<Link | ||
sx={{ | ||
textDecoration: 'none', | ||
color: ({ palette }) => palette.text.primary, | ||
}} | ||
onClick={auth?.removeUser} | ||
> | ||
Sign Out | ||
</Link> | ||
); | ||
} | ||
|
||
return ( | ||
<Box> | ||
<Button> | ||
<Link | ||
className={classes.buttonStyle} | ||
sx={{ | ||
textDecoration: 'none', | ||
'& :hover': { | ||
color: ({ palette }) => palette.text.primary, | ||
}, | ||
}} | ||
onClick={auth?.removeUser} | ||
> | ||
<Typography className={classes.buttonStyle}>Sign Out</Typography> | ||
</Link> | ||
</Button> | ||
</Box> | ||
); | ||
} | ||
|
||
export default SignOutButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Box, Link, Avatar, Typography } from '@mui/material'; | ||
|
||
function UserAvatar({ auth }) { | ||
if (!auth?.isAuthenticated) { | ||
return null; | ||
} | ||
return ( | ||
<Box> | ||
<Link | ||
href="https://dev-k8s.treetracker.org/keycloak/realms/treetracker/account/#/personal-info" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
sx={{ | ||
color: ({ palette }) => palette.text.primary, | ||
}} | ||
> | ||
<Avatar | ||
sx={{ | ||
width: 24, | ||
height: 24, | ||
background: ({ palette }) => palette.background.greenGradient, | ||
}} | ||
> | ||
<Typography | ||
variant="caption" | ||
sx={{ | ||
textTransform: 'uppercase', | ||
fontSize: 16, | ||
textDecoration: 'none', | ||
color: ({ palette }) => palette.text.contrast, | ||
}} | ||
> | ||
{auth?.user?.profile.preferred_username[0] || null} | ||
</Typography> | ||
</Avatar> | ||
</Link> | ||
</Box> | ||
); | ||
} | ||
|
||
export default UserAvatar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const oidcConfig = { | ||
authority: process.env.NEXT_PUBLIC_KEYCLOAK_URL, | ||
client_id: process.env.NEXT_PUBLIC_KEYCLOAK_CLIENT_ID, | ||
redirect_uri: process.env.NEXT_PUBLIC_KEYCLOAK_REDIRECT_URI, | ||
realm: process.env.NEXT_PUBLIC_KEYCLOAK_REALM, | ||
onSigninCallback: (res) => { | ||
console.log('onSigninCallback', res); | ||
localStorage.setItem('res', JSON.stringify(res)); | ||
}, | ||
}; | ||
|
||
export default oidcConfig; |
Oops, something went wrong.