-
Notifications
You must be signed in to change notification settings - Fork 198
feat: implementation of logout functionality #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
43e30af
feat: implement authentication context and login button, refactor App…
Akhileswara-Microsoft ed29c57
feat: pass userName prop to AppHeader component for personalized display
Akhileswara-Microsoft cd4a946
feat: enhance LoginButton with user initials and tooltip, update Auth…
Akhileswara-Microsoft 88f9f12
refactor: remove userName prop from AppHeader and App component
Akhileswara-Microsoft 49e5cb2
feat: refactor LoginButton to use Redux for user state management and…
Akhileswara-Microsoft accbc2c
fix: use httpClient.fetchExternal, reliable isAuthenticated, and aria…
Copilot 2fd8500
feat: enhance authentication logic and improve error handling in HTTP…
Akhileswara-Microsoft f122056
Merge branch 'LogoutFunctionality_Akhileswar' of https://github.com/m…
Akhileswara-Microsoft e4e4cc7
fix: improve user initials extraction and update display name logic i…
Akhileswara-Microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,133 @@ | ||
| import React, { useCallback } from 'react'; | ||
| import { | ||
| Avatar, | ||
| Menu, | ||
| MenuTrigger, | ||
| MenuPopover, | ||
| MenuList, | ||
| MenuItem, | ||
| Button, | ||
| makeStyles, | ||
| tokens, | ||
| } from '@fluentui/react-components'; | ||
| import { Person20Regular, SignOut24Regular } from '@fluentui/react-icons'; | ||
| import { useAppSelector } from '../store/hooks'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| userButton: { | ||
| minWidth: 'auto', | ||
| paddingLeft: tokens.spacingHorizontalXS, | ||
| paddingRight: tokens.spacingHorizontalXS, | ||
| }, | ||
| menuItem: { | ||
| paddingLeft: tokens.spacingHorizontalM, | ||
| paddingRight: tokens.spacingHorizontalM, | ||
| }, | ||
| userInfo: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'flex-start', | ||
| gap: tokens.spacingVerticalXXS, | ||
| }, | ||
| userName: { | ||
| fontWeight: tokens.fontWeightSemibold, | ||
| fontSize: tokens.fontSizeBase200, | ||
| }, | ||
| userEmail: { | ||
| fontSize: tokens.fontSizeBase100, | ||
| color: tokens.colorNeutralForeground2, | ||
| }, | ||
| }); | ||
|
|
||
| const getUserInitials = (name: string | undefined): string => { | ||
| if (!name) return 'U'; | ||
| const cleanName = name.replace(/\s*\([^)]*\)/g, '').trim(); | ||
| if (!cleanName) return 'U'; | ||
| const parts = cleanName.split(/\s+/).filter(Boolean); | ||
| if (parts.length >= 2) { | ||
| return (parts[0][0] + parts[1][0]).toUpperCase(); | ||
| } | ||
| return cleanName.charAt(0).toUpperCase(); | ||
|
Akhileswara-Microsoft marked this conversation as resolved.
|
||
| }; | ||
|
Akhileswara-Microsoft marked this conversation as resolved.
|
||
|
|
||
| const LoginButton: React.FC = () => { | ||
| const styles = useStyles(); | ||
| const userName = useAppSelector(state => state.app.userName); | ||
| const userId = useAppSelector(state => state.app.userId); | ||
| const userEmail = useAppSelector(state => state.app.userEmail); | ||
| const isAuthenticated = Boolean(userId && userId !== 'anonymous'); | ||
|
|
||
| const login = useCallback(() => { | ||
| window.location.href = '/.auth/login/aad'; | ||
| }, []); | ||
|
|
||
| const logout = useCallback(() => { | ||
| const logoutUrl = '/.auth/logout?post_logout_redirect_uri=' + encodeURIComponent('/'); | ||
| window.location.href = logoutUrl; | ||
| }, []); | ||
|
|
||
| const displayName = isAuthenticated ? userName || userId || 'User' : 'User'; | ||
|
|
||
| if (!isAuthenticated) { | ||
| return ( | ||
| <Button | ||
| appearance="subtle" | ||
| className={styles.userButton} | ||
| onClick={login} | ||
| title="Sign in" | ||
|
Akhileswara-Microsoft marked this conversation as resolved.
|
||
| aria-label="Sign in" | ||
| icon={ | ||
| <Avatar | ||
| name={displayName} | ||
| initials={getUserInitials(displayName)} | ||
| size={28} | ||
| color="colorful" | ||
| style={{ fontWeight: 'bold' }} | ||
| /> | ||
| } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Menu> | ||
| <MenuTrigger disableButtonEnhancement> | ||
| <Button | ||
| appearance="subtle" | ||
| className={styles.userButton} | ||
| title={`Signed in as ${displayName}`} | ||
|
Akhileswara-Microsoft marked this conversation as resolved.
|
||
| aria-label={`User menu for ${displayName}`} | ||
| icon={ | ||
| <Avatar | ||
| name={displayName} | ||
| initials={getUserInitials(displayName)} | ||
| size={28} | ||
| color="colorful" | ||
| style={{ fontWeight: 'bold' }} | ||
| /> | ||
| } | ||
| /> | ||
| </MenuTrigger> | ||
|
Akhileswara-Microsoft marked this conversation as resolved.
|
||
|
|
||
| <MenuPopover> | ||
| <MenuList> | ||
| <MenuItem className={styles.menuItem} icon={<Person20Regular />} disabled style={{ cursor: 'default' }}> | ||
| <div className={styles.userInfo}> | ||
| <div className={styles.userName}>{displayName}</div> | ||
| {userEmail && <div className={styles.userEmail}>{userEmail}</div>} | ||
| </div> | ||
| </MenuItem> | ||
| <MenuItem | ||
| className={styles.menuItem} | ||
| icon={<SignOut24Regular />} | ||
| onClick={logout} | ||
| > | ||
| Sign out | ||
| </MenuItem> | ||
| </MenuList> | ||
| </MenuPopover> | ||
| </Menu> | ||
| ); | ||
| }; | ||
|
|
||
| export default LoginButton; | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.