-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f52acc4
commit f3f23c3
Showing
7 changed files
with
99 additions
and
39 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
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 |
---|---|---|
|
@@ -21,6 +21,16 @@ yarn add @logto/browser | |
|
||
```bash | ||
pnpm add @logto/browser | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="cdn" label="CDN"> | ||
|
||
```html | ||
// Special thanks to jsdelivr | ||
<script type="module"> | ||
import LogtoClient from 'https://cdn.jsdelivr.net/npm/@logto/[email protected]/+esm'; | ||
</script> | ||
``` | ||
|
||
</TabItem> | ||
|
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
59 changes: 54 additions & 5 deletions
59
docs/quick-starts/framework/vanilla-js/_get-user-information.mdx
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 |
---|---|---|
@@ -1,9 +1,58 @@ | ||
import GetUserInfoApis from '../../fragments/_get-user-info-apis.mdx'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
|
||
import ClaimsNeedNetworkRequest from '../../fragments/_claims-need-network-request.mdx'; | ||
import FindUserInfoMissing from '../../fragments/_find-user-info-missing.mdx'; | ||
import ScopesAndClaims from '../../fragments/_scopes-and-claims.mdx'; | ||
import ScopesAndClaimsIntroduction from '../../fragments/_scopes-claims-introduction.md'; | ||
|
||
### Display user information | ||
|
||
```js title="Home.js" | ||
const userInfo = await logtoClient.getIdTokenClaims(); | ||
``` | ||
|
||
To display the user's information, you can use the `logtoClient.getIdTokenClaims()` method. For example, in your Home page: | ||
|
||
### Request additional claims | ||
|
||
<FindUserInfoMissing method="getIdTokenClaims()" /> | ||
|
||
<ScopesAndClaimsIntroduction /> | ||
|
||
To request additional scopes, you can configure the Logto configs: | ||
|
||
```js title="index.js" | ||
import LogtoClient, { UserScope } from '@logto/browser'; | ||
|
||
const logtoClient = new LogtoClient({ | ||
appId: '<your-application-id>', | ||
endpoint: '<your-logto-endpoint>', | ||
scopes: [ | ||
UserScope.Email, | ||
UserScope.Phone, | ||
UserScope.CustomData, | ||
UserScope.Identities, | ||
UserScope.Organizations, | ||
], | ||
}); | ||
``` | ||
|
||
Then you can access the additional claims in the return value of `logtoClient.getIdTokenClaims()`: | ||
|
||
```ts | ||
const claims = await getIdTokenClaims(); | ||
// Now you can access additional claims `claims.email`, `claims.phone`, etc. | ||
``` | ||
|
||
import ScopesAndClaimsCode from './code/_scopes-and-claims-code.mdx'; | ||
<ClaimsNeedNetworkRequest | ||
type="method" | ||
method="logtoClient.fetchUserInfo()" | ||
codeSnippet={ | ||
<CodeBlock language="js">{`const userInfo = await logtoClient.fetchUserInfo(); | ||
// Now you can access the claim \`userInfo.custom_data\``}</CodeBlock> | ||
} | ||
/> | ||
|
||
<GetUserInfoApis getIdTokenClaimsApi="getIdTokenClaims" fetchUserInfoApi="fetchUserInfo" /> | ||
### Scopes and claims | ||
|
||
<ScopesAndClaims configScopesCode={<ScopesAndClaimsCode package={props.package} />} /> | ||
./code/_scopes-and-claims-code.mdx./code/_config-resources-with-shared-scopes-code.mdx./code/_config-resources-with-scopes-code.mdx./code/_config-organization-code.mdx | ||
<ScopesAndClaims /> |
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
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