/Knowledge/sources/honojs__hono/examples/stytch-auth-src-auth-tsx--b88c21e3b25f.md
Example: stytch-auth/src/Auth.tsx - hono-docs
Example: stytch auth/src/Auth.tsx Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://raw.githubusercontent.com/honojs/examples/m...
Example: stytch-auth/src/Auth.tsx
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://raw.githubusercontent.com/honojs/examples/main/stytch-auth/src/Auth.tsx
Summary
import {OAuthProviders, OTPMethods, Products, StytchEvent, StytchLoginConfig} from "@stytch/vanilla-js"; import {IdentityProvider, StytchLogin, useStytch, useStytchUser} from "@stytch/react"; import {useEffect, useMemo} from "react"; /**...
Content
import {OAuthProviders, OTPMethods, Products, StytchEvent, StytchLoginConfig} from "@stytch/vanilla-js"; import {IdentityProvider, StytchLogin, useStytch, useStytchUser} from "@stytch/react"; import {useEffect, useMemo} from "react";
/**
- A higher-order component that enforces a login requirement for the wrapped component.
- If the user is not logged in, the user is redirected to the login page and the
- current URL is stored in localStorage to enable return after authentication. */ export const withLoginRequired = (Component: React.FC) => () => { const {user, fromCache} = useStytchUser()
useEffect(() => { if (!user && !fromCache) { localStorage.setItem('returnTo', window.location.href); window.location.href = '/login'; } }, [user, fromCache])
if (!user) { return null } return <Component/> }
Metadata
{
"chunk_index": 0,
"citation": "https://raw.githubusercontent.com/honojs/examples/main/stytch-auth/src/Auth.tsx",
"coverage_role": "examples",
"qualified_title": "Hono / examples / stytch-auth/src/Auth.tsx (1)",
"repo_path": "stytch-auth/src/Auth.tsx",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 0,
"source_id": "/honojs/hono",
"source_type": "examples",
"target_label": "examples",
"title": "Example: stytch-auth/src/Auth.tsx",
"upstream_url": "https://raw.githubusercontent.com/honojs/examples/main/stytch-auth/src/Auth.tsx",
"version": "2026"
}