Accessing Authenticated User Data

This guide will help you access information of authenticated users.

Requirements

To follow the steps in this tutorial, you should be familiar with the required directory structure for your codebase, and understand the concepts of pages and users, and GraphQL. To have information stored of authenticated users that you can access, make sure you have followed the previous tutorials in the Get Started/Users section.

Steps

Accessing authenticated user data is a two-step process:

Step 1: Create GraphQL query

app/graph_queries/current_user.graphql

{
  current_user {
    id
    slug
    first_name
    email
    developer_profile: profile(profile_type: "developer") {
      id
    }
    client_profile: profile(profile_type: "client") {
      id
    }
  }
}

Step 2: Fetch information from GraphQL file

On any given page (including layout itself, but be careful with adding queries to the layout), you can add this liquid tag:


{% graphql g = 'current_user' %}

This tag fetches information defined in the GraphQL file for the currently logged in user and stores it in a variable named g. The returned data is a standard hash, so you can even display it via {{ g }}.

Next steps

Congratulations! You know how to access information of authenticated users. Now you can learn about sending an Email Notification to a newly signed up user:

Questions?

We are always happy to help with any questions you may have.