Docs

Read session and user data with Expo

Clerk provides a set of React hooks and helpers that you can use to access active session and user data in your Expo application. The examples in this guide will demonstrate how to use some of these helpers.

See the React Client-side Helpers reference guides for more information.

Session data example

useAuth() gives you access to the current auth state. This hook provides the minimal information needed for data-loading and 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()

  // In case the user signs out while on the page.
  if (!isLoaded || !userId) {
    return null
  }

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

User data example

useUser() 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} welcome to Clerk</Text>
}

Feedback

What did you think of this content?

Last updated on