-
Notifications
You must be signed in to change notification settings - Fork 2.7k
msal-react #1: account changes #2356
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 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
35d27ad
Update useIsAuthenticated to use account
tnorling 1adc4c1
Merge branch 'msal-react-feature-branch' of https://github.com/AzureA…
tnorling 88f948a
add AccountIdentifiers object
tnorling cc84a3c
update import
tnorling 37b3b70
Update references to account
tnorling 7409d91
move stub instance to msal-browser
tnorling a2ac903
Merge branch 'msal-react-feature-branch' of https://github.com/AzureA…
tnorling b1a7c4c
Update template props
tnorling 0f72b77
Merge branch 'msal-react-feature-branch' of https://github.com/AzureA…
tnorling d6cb37c
Merge branch 'msal-react-feature-branch' of https://github.com/AzureA…
tnorling e58bf05
Merge branch 'msal-react-feature-branch' of https://github.com/AzureA…
tnorling b68941e
Update dependency
tnorling d1b5180
Fix lint
tnorling 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
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 |
---|---|---|
@@ -1,33 +1,46 @@ | ||
{ | ||
"name": "@azure/msal-react", | ||
"version": "0.0.1", | ||
"author": { | ||
"name": "Microsoft", | ||
"email": "[email protected]", | ||
"url": "https://www.microsoft.com" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git" | ||
}, | ||
"description": "Microsoft Authentication Library for React", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src" | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test --passWithNoTests", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"build:modules:watch": "tsdx watch --verbose", | ||
"test": "tsdx test .*.spec.*", | ||
"lint": "cd ../../ && npm run lint:react", | ||
"lint:fix": "npm run lint -- -- --fix", | ||
"build:all": "npm run build:common && npm run build:browser && npm run build", | ||
"build:browser": "cd ../msal-browser && npm run build", | ||
"build:common": "cd ../msal-common && npm run build", | ||
"prepack": "npm run build:all", | ||
"storybook": "start-storybook -p 6006", | ||
"build-storybook": "build-storybook" | ||
}, | ||
"peerDependencies": { | ||
"@azure/msal-browser": "^2.0.0", | ||
"@azure/msal-browser": "^2.2.0", | ||
"react": ">=16" | ||
}, | ||
"name": "@azure/msal-react", | ||
"author": "Jason Nutter", | ||
"module": "dist/msal-react.esm.js", | ||
"devDependencies": { | ||
"@azure/msal-browser": "^2.0.0", | ||
"@azure/msal-browser": "^2.2.0", | ||
"@babel/core": "^7.10.5", | ||
"@storybook/addon-actions": "^5.3.19", | ||
"@storybook/addon-docs": "^5.3.19", | ||
|
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
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 |
---|---|---|
@@ -1,21 +1,34 @@ | ||
import { AccountInfo, IPublicClientApplication } from "@azure/msal-browser"; | ||
import { useState, useEffect } from "react"; | ||
|
||
import { useMsal } from "./MsalProvider"; | ||
import { isAuthenticated } from "./utilities"; | ||
|
||
export function useIsAuthenticated(username?: string): boolean { | ||
export type AccountIdentifiers = Partial<Pick<AccountInfo, "homeAccountId"|"username">>; | ||
|
||
function isAuthenticated(instance: IPublicClientApplication, account?: AccountIdentifiers): boolean { | ||
if (account?.homeAccountId) { | ||
return !!instance.getAccountByHomeId(account.homeAccountId); | ||
} else if (account?.username) { | ||
return !!instance.getAccountByUsername(account.username); | ||
} | ||
|
||
return instance.getAllAccounts().length > 0; | ||
} | ||
|
||
export function useIsAuthenticated(account?: AccountIdentifiers): boolean { | ||
const { | ||
state: { accounts }, | ||
instance, | ||
} = useMsal(); | ||
|
||
const [hasAuthenticated, setHasAuthenticated] = useState<boolean>( | ||
isAuthenticated(instance, username) | ||
isAuthenticated(instance, account) | ||
); | ||
|
||
useEffect(() => { | ||
const result = isAuthenticated(instance, username); | ||
const result = isAuthenticated(instance, account); | ||
setHasAuthenticated(result); | ||
}, [accounts, username, instance]); | ||
}, [accounts, account, instance]); | ||
|
||
return hasAuthenticated; | ||
} |
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
Oops, something went wrong.
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.