1
1
import { AuthStateType } from '@sanity/sdk'
2
2
import { useAuthState , useCurrentUser } from '@sanity/sdk-react/hooks'
3
3
import { Avatar , Card , Container , Flex , Grid , Stack , Text } from '@sanity/ui'
4
+ import ExampleLayout from '../../ExampleLayout'
4
5
5
6
export default function UserProfile ( ) {
6
7
// Use the `useAuthState` hook to ensure there's currently a logged in user
@@ -12,34 +13,41 @@ export default function UserProfile() {
12
13
13
14
// Render a user profile if the authentication state indicated a logged in user and a user object is available
14
15
return type === AuthStateType . LOGGED_IN && user ? (
15
- < Container width = { 1 } >
16
- < Card padding = { 4 } margin = { 2 } radius = { 3 } shadow = { 3 } >
17
- < Flex justify = 'center' marginBottom = { 5 } >
18
- < Avatar src = { user ?. profileImage } size = { 3 } />
19
- </ Flex >
20
- < Text as = 'h2' size = { 4 } weight = 'medium' align = 'center' >
21
- { user ?. name }
22
- </ Text >
23
- < Stack space = { 3 } marginTop = { 5 } marginBottom = { 4 } >
24
- < Grid columns = { 2 } gap = { 4 } as = 'dl' >
25
- < Text as = 'dt' align = 'right' muted >
26
- Email address
27
- </ Text >
28
- < Text as = 'dd' > { user ?. email } </ Text >
29
- < Text as = 'dt' align = 'right' muted >
30
- Roles
31
- </ Text >
32
- < Text as = 'dd' >
33
- { user ?. roles . map ( ( role ) => role . title ) . join ( ', ' ) }
34
- </ Text >
35
- < Text as = 'dt' align = 'right' muted >
36
- Provider
37
- </ Text >
38
- < Text as = 'dd' > { user ?. provider } </ Text >
39
- </ Grid >
40
- </ Stack >
41
- </ Card >
42
- </ Container >
16
+ < ExampleLayout
17
+ title = 'User profile'
18
+ codeUrl = 'https://github.com/sanity-io/sdk-examples/blob/main/sdk-explorer/src/users/UserProfile/UserProfile.tsx'
19
+ hooks = { [ 'useAuthState' , 'useCurrentUser' ] }
20
+ styling = 'Sanity UI'
21
+ >
22
+ < Container width = { 1 } >
23
+ < Card padding = { 4 } margin = { 2 } radius = { 3 } shadow = { 3 } >
24
+ < Flex justify = 'center' marginBottom = { 5 } >
25
+ < Avatar src = { user ?. profileImage } size = { 3 } />
26
+ </ Flex >
27
+ < Text as = 'h2' size = { 4 } weight = 'medium' align = 'center' >
28
+ { user ?. name }
29
+ </ Text >
30
+ < Stack space = { 3 } marginTop = { 5 } marginBottom = { 4 } >
31
+ < Grid columns = { 2 } gap = { 4 } as = 'dl' >
32
+ < Text as = 'dt' align = 'right' muted >
33
+ Email address
34
+ </ Text >
35
+ < Text as = 'dd' > { user ?. email } </ Text >
36
+ < Text as = 'dt' align = 'right' muted >
37
+ Roles
38
+ </ Text >
39
+ < Text as = 'dd' >
40
+ { user ?. roles . map ( ( role ) => role . title ) . join ( ', ' ) }
41
+ </ Text >
42
+ < Text as = 'dt' align = 'right' muted >
43
+ Provider
44
+ </ Text >
45
+ < Text as = 'dd' > { user ?. provider } </ Text >
46
+ </ Grid >
47
+ </ Stack >
48
+ </ Card >
49
+ </ Container >
50
+ </ ExampleLayout >
43
51
) : (
44
52
// Render a placeholder if there's no user currently logged in
45
53
< Container padding = { 5 } >
0 commit comments