Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TocTocAuthProvider
✓ import { TocTocAuthProvider } from 'toctoc-auth'
✗ import TocTocAuthProvider from 'toctoc-auth'
Named export, not default. Since v1.0.
useTocTocAuth
✓ import { useTocTocAuth } from 'toctoc-auth'
Hook must be used inside a TocTocAuthProvider context. Named export.
isTokenExpired
✓ import { isTokenExpired } from 'toctoc-auth'
✗ import { isTokenExpired } from 'toctoc-auth/utils'
Utility function exported from main package. Not a subpath.
Minimal setup: wrap app with TocTocAuthProvider, then use useTocTocAuth hook for credentials-based sign-in.
import { TocTocAuthProvider, useTocTocAuth } from 'toctoc-auth';
import { BrowserRouter } from 'react-router-dom';
const authConfig = {
apiBaseUrl: process.env.AUTH_API_URL ?? 'http://localhost:4000',
encryptionKey: process.env.ENCRYPTION_KEY ?? 'default-dev-key-32chars!!',
providers: {
credentials: {
signUpApiRoute: '/auth/register',
signInApiRoute: '/auth/login',
refreshTokenApiRoute: '/auth/refresh',
signInAfterSignUp: false,
redirectClientRoutes: {
afterSignUp: '/dashboard',
afterSignIn: '/dashboard',
afterSignOut: '/login'
},
signInJsonResponseAccessTokenLocation: ['accessToken'],
signInJsonResponseRefreshTokenLocation: ['refreshToken'],
signInJsonResponseUser: {
location: ['user'],
roleLocation: ['role']
}
}
}
};
function App() {
return (
<BrowserRouter>
<TocTocAuthProvider config={authConfig}>
<YourApp />
</TocTocAuthProvider>
</BrowserRouter>
);
}
function LoginForm() {
const { signInWithCredentialsAsync, isAuthenticating, user } = useTocTocAuth();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const res = await signInWithCredentialsAsync({ email: 'a@b.com', password: 'secret' });
if (res.isSuccess) console.log('Logged in');
else console.error(res.responseBody);
};
return (
<form onSubmit={handleSubmit}>
<button disabled={isAuthenticating}>Sign In</button>
</form>
);
}
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'signInWithCredentialsAsync')
Component not wrapped in TocTocAuthProvider, or useTocTocAuth called outside provider.
fixWrap the component tree with <TocTocAuthProvider config={...}> at the root. TypeError: (0 , toctoc_auth.useTocTocAuth) is not a function
Default import instead of named import.
fixUse import { useTocTocAuth } from 'toctoc-auth' instead of import useTocTocAuth from 'toctoc-auth'. Audit
Dependencies
reactrequiredPeer dependency for React components and hooks
react-domrequiredPeer dependency for DOM rendering
react-router-domrequiredPeer dependency for routing and protected routes