
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
@rubriclab/auth
Advanced tools
An agent-native, type-safe authorization and authentication library for Next.js applications.
By separating notions of authentication ("who am I?") and authorization ("what can I do?"), we can scale apps to dozens of integrations while maintaining a simple, type-safe API.
bun add @rubriclab/auth
Choose between Prisma or Drizzle:
// Using Prisma
import { prismaAdapter } from '@rubriclab/auth/providers/prisma'
import { PrismaClient } from '@prisma/client'
import { env } from '@/env'
const prisma = new PrismaClient()
const databaseProvider = prismaAdapter(prisma)
// OR using Drizzle
import { drizzleAdapter } from '@rubriclab/auth/providers/drizzle'
import { drizzle } from 'drizzle-orm/neon-serverless'
const db = drizzle(env.DATABASE_URL)
const databaseProvider = drizzleAdapter(db)
// lib/auth/server.ts
import { createAuth } from '@rubriclab/auth'
import { createGithubAuthenticationProvider } from '@rubriclab/auth/providers/github'
import { createGoogleAuthenticationProvider } from '@rubriclab/auth/providers/google'
import { createResendMagicLinkAuthenticationProvider } from '@rubriclab/auth/providers/resend'
export const { routes, actions } = createAuth({
databaseProvider,
authUrl: env.NEXT_PUBLIC_AUTH_URL, // e.g., 'https://yourdomain.com'
// OAuth2 Authentication Providers
oAuth2AuthenticationProviders: {
github: createGithubAuthenticationProvider({
githubClientId: env.GITHUB_CLIENT_ID,
githubClientSecret: env.GITHUB_CLIENT_SECRET,
}),
google: createGoogleAuthenticationProvider({
googleClientId: env.GOOGLE_CLIENT_ID,
googleClientSecret: env.GOOGLE_CLIENT_SECRET,
}),
},
// Magic Link Authentication Providers
magicLinkAuthenticationProviders: {
resend: createResendMagicLinkAuthenticationProvider({
resendApiKey: env.RESEND_API_KEY,
fromEmail: 'noreply@yourdomain.com',
subject: 'Sign in to Your App',
html: (url) => `
<h1>Welcome to Your App</h1>
<p>Click the link below to sign in:</p>
<a href="${url}">Sign In</a>
`,
}),
},
})
// lib/auth/actions.ts
'use server'
import { actions } from '@/lib/auth/server'
export const { signIn, signOut, sendMagicLink, getAuthConstants, getSession } = actions
// lib/auth/client.ts
'use client'
import { CreateAuthContext } from '@rubriclab/auth/client'
import type { DrizzleSession } from '@rubriclab/auth/providers/drizzle'
// or (prisma): import type { User } from '@prisma/client'
import type { users } from '@/lib/db/schema/auth'
export const { ClientAuthProvider, useSession } =
CreateAuthContext<DrizzleSession<typeof users.$inferSelect>>()
// or (prisma): CreateAuthContext<User>()
Create an API route handler for authentication:
// app/api/auth/[...auth]/route.ts
import { routes } from '@/lib/auth/server'
export const { GET } = routes
// Server Component
import { getSession } from '@/lib/auth/actions'
export default async function DashboardPage() {
const session = await getSession({
redirectUnauthorized: '/login'
})
return (
<div>
<h1>Welcome, {session.user.email}!</h1>
{/* Your dashboard content */}
</div>
)
}
// Client Component
'use client'
import { CreateAuthContext, useSession } from '@/lib/auth/client'
export function DashboardClient({ session }: { session: typeof session }) {
return (
<ClientAuthProvider session={session}>
<DashboardContent />
</ClientAuthProvider>
)
}
function DashboardContent() {
const session = useSession()
return (
<div>
<h2>Connected Accounts:</h2>
<ul>
{session.user.oAuth2AuthenticationAccounts.map(account => (
<li key={account.accountId}>{account.provider}</li>
))}
</ul>
</div>
)
}
import { signIn, sendMagicLink, signOut } from '@/lib/auth/actions'
// Sign in with OAuth2
await signIn({
provider: 'github',
callbackUrl: '/dashboard'
})
// Send magic link
await sendMagicLink({
provider: 'resend',
email: 'user@example.com'
})
// Sign out
await signOut({ redirect: '/' })
# Your application's base URL for auth callbacks
NEXT_PUBLIC_AUTH_URL=https://yourdomain.com
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
RESEND_API_KEY=your_resend_api_key
GitHub (@rubriclab/auth/providers/github)
read:user, user:email (default)Google (@rubriclab/auth/providers/google)
userinfo.email, userinfo.profile (default)@rubriclab/auth/providers/resend)
GitHub (@rubriclab/auth/providers/github)
repo, admin:org, workflow, packages, etc.Google (@rubriclab/auth/providers/google)
gmail.readonly, drive.file, calendar.events, etc.Brex (@rubriclab/auth/providers/brex)
Vercel (@rubriclab/auth/providers/vercel)
Prisma (@rubriclab/auth/providers/prisma)
Drizzle (@rubriclab/auth/providers/drizzle)
The library requires the following database tables:
users - User accountssessions - User sessionsoauth2_authentication_requests - OAuth2 authentication flow stateoauth2_authorization_requests - OAuth2 authorization flow statemagic_link_requests - Magic link authentication stateoauth2_authentication_accounts - Connected OAuth2 authentication accountsoauth2_authorization_accounts - Connected OAuth2 authorization accountsapi_key_authorization_accounts - Connected API key authorization accountsimport { createOauth2AuthenticationProvider } from '@rubriclab/auth'
const customProvider = createOauth2AuthenticationProvider({
getAuthenticationUrl: async ({ redirectUri, state }) => {
const url = new URL('https://your-provider.com/oauth/authorize')
url.searchParams.set('client_id', process.env.CUSTOM_CLIENT_ID!)
url.searchParams.set('redirect_uri', redirectUri)
url.searchParams.set('state', state)
url.searchParams.set('scope', 'read:user')
return url
},
getToken: async ({ code, redirectUri }) => {
// Implement token exchange
return {
accessToken: 'token',
refreshToken: 'refresh',
expiresAt: new Date(Date.now() + 3600000)
}
},
getUser: async ({ accessToken }) => {
// Implement user info retrieval
return {
accountId: 'user_id',
email: 'user@example.com'
}
},
refreshToken: async ({ refreshToken }) => {
// Implement token refresh
return {
accessToken: 'new_token',
refreshToken: 'new_refresh',
expiresAt: new Date(Date.now() + 3600000)
}
}
})
The library provides full TypeScript support with strict typing:
// Session type inference
const session = await auth.actions.getSession({ redirectUnauthorized: '/login' })
// session.user.email is typed as string
// session.user.oAuth2AuthenticationAccounts is typed as array
// Provider type safety
await auth.actions.signIn({
provider: 'github', // TypeScript will ensure this is a valid provider
callbackUrl: '/dashboard'
})
FAQs
Unknown package
The npm package @rubriclab/auth receives a total of 14 weekly downloads. As such, @rubriclab/auth popularity was classified as not popular.
We found that @rubriclab/auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.