useStytchSession hook.
If no User is signed in, the returned value will be null.
In non-React environments, use the session.getSync method to get the Session.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
import { useStytchSession } from '@stytch/nextjs';
export const SessionInfo = () => {
const { session, isInitialized } = useStytchSession();
if (!isInitialized) {
return <p>Loading...</p>;
}
return session ? <p>Session ID: {session.session_id}</p> : <p>No active session</p>;
};
{
"session": { ... },
"isInitialized": true,
"fromCache": false
}
{
"session": null,
"isInitialized": false,
"fromCache": false
}
{
"session": null,
"isInitialized": true,
"fromCache": false
}
import { useStytchSession } from '@stytch/nextjs';
export const SessionInfo = () => {
const { session, isInitialized } = useStytchSession();
if (!isInitialized) {
return <p>Loading...</p>;
}
return session ? <p>Session ID: {session.session_id}</p> : <p>No active session</p>;
};
{
"session": { ... },
"isInitialized": true,
"fromCache": false
}
{
"session": null,
"isInitialized": false,
"fromCache": false
}
{
"session": null,
"isInitialized": true,
"fromCache": false
}
Access the current session state using the Stytch Next.js SDK
import { useStytchSession } from '@stytch/nextjs';
export const SessionInfo = () => {
const { session, isInitialized } = useStytchSession();
if (!isInitialized) {
return <p>Loading...</p>;
}
return session ? <p>Session ID: {session.session_id}</p> : <p>No active session</p>;
};
{
"session": { ... },
"isInitialized": true,
"fromCache": false
}
{
"session": null,
"isInitialized": false,
"fromCache": false
}
{
"session": null,
"isInitialized": true,
"fromCache": false
}
import { useStytchSession } from '@stytch/nextjs';
export const SessionInfo = () => {
const { session, isInitialized } = useStytchSession();
if (!isInitialized) {
return <p>Loading...</p>;
}
return session ? <p>Session ID: {session.session_id}</p> : <p>No active session</p>;
};
{
"session": { ... },
"isInitialized": true,
"fromCache": false
}
{
"session": null,
"isInitialized": false,
"fromCache": false
}
{
"session": null,
"isInitialized": true,
"fromCache": false
}
useStytchSession hook.
If no User is signed in, the returned value will be null.
In non-React environments, use the session.getSync method to get the Session.
Show properties