Skip to main content
Which UI do you use?
Custom UI
Pre built UI

Get User Info

You can fetch user information on the backend as well as on the frontend.

Fetching on the backend#

Using getUserByEmail#

You can get a user's information on the backend using the getUsersByEmail and getUserById functions:

import ThirdParty from "supertokens-node/recipe/thirdparty";

async function getUserInfo() {
// Note that usersInfo has type User[]
// You can learn more about the `User` object over here https://github.com/supertokens/core-driver-interface/wiki
let usersInfo = await ThirdParty.getUsersByEmail("test@example.com");
}

Using getUserById#

import express from "express";
import ThirdParty from "supertokens-node/recipe/thirdparty";
import { verifySession } from "supertokens-node/recipe/session/framework/express";
import { SessionRequest } from 'supertokens-node/framework/express';

let app = express();
app.get("/get-user-info", verifySession(), async (req: SessionRequest, res) => {
let userId = req.session!.getUserId();
// You can learn more about the `User` object over here https://github.com/supertokens/core-driver-interface/wiki
let userInfo = await ThirdParty.getUserById(userId)
// ...
})

Fetching on the frontend#

important

The function calls below require no API calls and read directly from the session information stored on the frontend. This makes them very quick.

import React from "react";
import { useSessionContext } from 'supertokens-auth-react/recipe/session';

// Your dashboard component
function Dashboard(props: any) {
let session = useSessionContext();

if (session.loading) {
return null;
}

let {doesSessionExist, userId, accessTokenPayload} = session;

// doesSessionExist will always be true if this is wrapped in `<SessionAuth>`
if (!doesSessionExist) {
// TODO
}

let name = accessTokenPayload.userName;
}