Advanced Topics
Get Session Data

Get Data on The Current Session


If you want to access the current user's data, e.g., to show the user's first name, you can either use the useSession hook or an async helper.


import { useSession } from "@roq/ui-react";
const { session, status } = useSession();
const firstName = session.user.firstName;

This method is used to refetch the current token & session data (e.g., after a user updates their profile).

import { useRoqComponents } from "@roq/ui-react";
function Button() {
  const { refetchSession } = useRoqComponents();
  return <button onClick={refetchSession}>Refetch session</button>;

Async Helper

import { getSession } from "@roq/ui-react";
const user = await getSession();
const firstName = user.session.user.firstName;


You can access the current user's data using this request handler:

import { getServerSession } from "@roq/nextjs";
async function handler(req: NextApiRequest, res: NextApiResponse) {
  const session = getServerSession(req);
  const user = session.user;