Authentication abstraction for DemoKit - Supabase Auth with provider interface
npm install @demokit-ai/authAuthentication abstraction for DemoKit with Supabase Auth integration and extensible provider interface.
``bash`
npm install @demokit-ai/auth @supabase/supabase-js
- AuthProvider - React context for authentication stateDemoAuthProvider
- - Demo mode authentication with mock usersuseAuth
- - Hook for accessing auth state and methodsuseUser
- - Hook for accessing current useruseSession
- - Hook for accessing session data
- Supabase Auth integration out of the box
- Full TypeScript support
`tsx
import { AuthProvider } from '@demokit-ai/auth'
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_ANON_KEY!
)
function App() {
return (
)
}
`
Use mock authentication for demos:
`tsx
import { DemoAuthProvider } from '@demokit-ai/auth'
const demoUsers = [
{ id: '1', email: 'demo@example.com', name: 'Demo User' },
{ id: '2', email: 'admin@example.com', name: 'Admin User', role: 'admin' },
]
function App() {
return (
)
}
`
`tsx
import { useAuth, useUser } from '@demokit-ai/auth'
function Profile() {
const { signOut, isLoading } = useAuth()
const user = useUser()
if (isLoading) return
return (
Welcome, {user.email}
$3
`tsx
import { useAuth } from '@demokit-ai/auth'
import { Navigate } from 'react-router-dom'function ProtectedRoute({ children }) {
const { user, isLoading } = useAuth()
if (isLoading) return
Loading...
if (!user) return return children
}
`API Reference
$3
Props:
-
client - Supabase client instance
- onAuthStateChange - Callback for auth state changes$3
Props:
-
users - Array of mock user objects
- defaultUser - ID of the default logged-in user
- onSignIn - Callback when a user signs in
- onSignOut - Callback when a user signs out$3
Returns:
-
user - Current user object
- session - Current session
- isLoading - Loading state
- signIn(credentials) - Sign in method
- signOut() - Sign out method
- signUp(credentials)` - Sign up methodReturns the current user object or null.
Returns the current session object or null.
MIT