Authentication
HiveForge uses Supabase Auth for secure, scalable authentication.
Supported Methods
- Email/Password
- Magic Links
- Google OAuth
- GitHub OAuth
- SAML SSO (Enterprise)
Quick Start
Sign Up
import { createClient } from '@/lib/supabase/client'
const supabase = createClient()
const { data, error } = await supabase.auth.signUp({
email: 'user@example.com',
password: 'securepassword',
options: {
data: {
full_name: 'John Doe',
},
},
})Sign In
const { data, error } = await supabase.auth.signInWithPassword({
email: 'user@example.com',
password: 'securepassword',
})OAuth
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: `${window.location.origin}/auth/callback`,
},
})Configuration
Configure in Supabase Studio:
- Go to Authentication > Providers
- Enable desired providers
- Add OAuth credentials
- Set redirect URLs
Protected Routes
// middleware.ts
import { createServerClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
export async function middleware(request: Request) {
const supabase = createServerClient()
const { data: { session } } = await supabase.auth.getSession()
if (!session) {
return NextResponse.redirect(new URL('/auth/login', request.url))
}
return NextResponse.next()
}
export const config = {
matcher: ['/dashboard/:path*', '/settings/:path*'],
}Session Management
Sessions are managed via HTTP-only cookies for security.
// Check session
const { data: { session } } = await supabase.auth.getSession()
// Refresh session
const { data: { session } } = await supabase.auth.refreshSession()
// Sign out
await supabase.auth.signOut()