const { data, error, loading } = useSession();
Use this hook to determine if the user is authenticated or not.
function Page() {
const { data, error, loading } = useSession();
if (loading) return <p>Loading...</p>;
if (error) return <p>Something went wrong.</p>;
switch (data.type) {
case SessionType.Anonymous:
// data is a AnonymousSession
return <Login />;
case SessionType.JustWallet:
// data is a WalletOnlySession
return <MyWallet address={data.address} />;
case SessionType.WithProfile:
// data is a ProfileSession
return <MyProfile profile={data.profile} />;
default:
return <p>Something went wrong.</p>;
}
}
You can enable suspense mode to suspend the component until the session data is available.
function Page() {
const { data } = useSession({ suspense: true });
switch (data.type) {
case SessionType.Anonymous:
// data is a AnonymousSession
return <Login />;
case SessionType.JustWallet:
// data is a WalletOnlySession
return <MyWallet address={data.address} />;
case SessionType.WithProfile:
// data is a ProfileSession
return <MyProfile profile={data.profile} />;
default:
return <p>Something went wrong.</p>;
}
}
Further session data updates will NOT trigger a suspense.
Optional
args: UseSessionArgs<never>
useSession
is a hook that lets you access the current Session