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 getUserByEmail, getUserByPhoneNumber and getUserById functions:


import Passwordless from "supertokens-node/recipe/passwordless";

async function handler() {
const userInfo = await Passwordless.getUserByEmail({email: "[email protected]"});
}

Using getUserByPhoneNumber#

import Passwordless from "supertokens-node/recipe/passwordless";

async function handler() {
const userInfo = await Passwordless.getUserByPhoneNumber({phoneNumber: "+1234567891"});
}

Using getUserById#

import express from "express";

import Passwordless from "supertokens-node/recipe/passwordless";
import { verifySession } from "supertokens-node/recipe/session/framework/express";

const app = express();

app.get("/get-user-info", verifySession(), async (req, res) => {
let userId = req.session.getUserId();

let userInfo = await Passwordless.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;
}