Docs

Read session and user data with Expo

This guide demonstrates how to access active session and user data in your Expo application.

Session data example

The useAuth() hook provides information about the current auth state, as well as helper methods to manage the current active session.

The following example demonstrates how to use useAuth() to get and display session and user data:

components/UseAuthExample.tsx
import { useAuth } from '@clerk/clerk-expo'
import { Text } from 'react-native'

export default function UseAuthExample() {
  const { isLoaded, userId, sessionId } = useAuth()

  if (!isLoaded || !userId) {
    return null
  }

  return (
    <Text>
      Hello, {userId} your current active session is {sessionId}
    </Text>
  )
}

User data example

The useUser() hook enables you to access the current user's data and provides helper methods to manage the current active session.

The following example demonstrates how to use useUser() to check if the user is signed in and display their first name:

component/UseUserExample.tsx
import { useUser } from '@clerk/clerk-expo'
import { Text } from 'react-native'

export default function UseUserExample() {
  const { isLoaded, isSignedIn, user } = useUser()

  if (!isLoaded || !isSignedIn) {
    return null
  }

  return <Text>Hello, {user.firstName}!</Text>
}

Feedback

What did you think of this content?

Last updated on