Skip to main content

Get User Info

On the Backend#

Using getUserByEmail#

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


let  ThirdPartyEmailPassword = require("supertokens-node/recipe/thirdpartyemailpassword");
// Note that usersInfo has type User[]// You can learn more about the `User` object over here https://github.com/supertokens/core-driver-interface/wikilet usersInfo = await ThirdPartyEmailPassword.getUsersByEmail("[email protected]");

Using getUserById#

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

On the Frontend#

Step 1: Wrap the component in which you want to get the info with ThirdPartyEmailPasswordAuth#

import { ThirdPartyEmailPasswordAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword';
render() {     return (           <ThirdPartyEmailPasswordAuth>                  <Dashboard />           </ThirdPartyEmailPasswordAuth>     );}

Step 2: This is how to use the session context in a component:#


import React from "react";import { useSessionContext } from 'supertokens-auth-react/recipe/session'; 
// Your dashboard componentfunction Dashboard(props) {    let {userId, accessTokenPayload} = useSessionContext();
    let role = accessTokenPayload.role;
    if (role === "admin") {        // TODO..    } else {        // TODO..    }}