
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@gftdcojp/auth
Advanced tools
Zero-config authentication package for Next.js applications with Firebase integration
🚀 Zero-config authentication package for Next.js applications with Firebase integration.
Published at: https://www.npmjs.com/package/@gftdcojp/auth
npm install @gftdcojp/auth
# or
yarn add @gftdcojp/auth
# or
pnpm add @gftdcojp/auth
Make sure you have the following environment variables configured:
# Firebase Admin SDK (Required for server-side operations)
FIREBASE_PROJECT_ID=your-firebase-project-id
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxx@your-project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
Note: If you're using this package within the GFTD ecosystem (@100_api/, @200_user/, @120_admin/), these environment variables are not needed as the infrastructure is managed centrally.
Create a .env.local
file with your Firebase configuration:
# Firebase Admin SDK (Required for server-side operations)
FIREBASE_PROJECT_ID=your-firebase-project-id
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxx@your-project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
// app/layout.tsx
'use client'
import { AuthProvider, createClientAuthConfig } from '@gftdcojp/auth'
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
// 🎯 Zero-config setup - no configuration needed!
const authConfig = createClientAuthConfig()
return (
<html lang="en">
<body>
<AuthProvider config={authConfig}>
{children}
</AuthProvider>
</body>
</html>
)
}
// app/page.tsx
'use client'
import { useAuth } from '@gftdcojp/ai-gftd-auth'
export default function HomePage() {
const { user, isLoading, logout, getAfterLoginUrl } = useAuth()
if (isLoading) return <div>Loading...</div>
if (!user) {
return (
<div>
<h1>Welcome!</h1>
<p>Please sign in to continue.</p>
<a href="/signin">Sign In</a>
</div>
)
}
return (
<div>
<h1>Welcome, {user.displayName}!</h1>
<p>Email: {user.email}</p>
<button onClick={() => logout().then(() => window.location.href = '/signin')}>
Logout
</button>
</div>
)
}
// Custom redirects for your application
const authConfig = createClientAuthConfig({
redirects: {
afterLogin: '/dashboard', // Custom login redirect
afterLogout: '/welcome', // Custom logout redirect
onAuthError: '/help', // Custom error redirect
}
})
// If you have a custom API server
const authConfig = createClientAuthConfig({
api: {
baseUrl: 'https://your-api-server.com',
loginEndpoint: '/api/custom/login',
sessionEndpoint: '/api/custom/session',
logoutEndpoint: '/api/custom/logout',
}
})
useAuth()
Returns authentication state and methods.
const {
user, // UserProfile | null
accessToken, // string | null
isLoading, // boolean
loginWithIdToken, // (idToken: string, tenantId?: string) => Promise<void>
logout, // () => Promise<void>
refreshToken, // () => Promise<void>
getAfterLoginUrl, // () => string
getAfterLogoutUrl, // () => string
getAuthErrorUrl, // () => string
} = useAuth()
createClientAuthConfig(overrides?)
Creates client-side authentication configuration.
createServerAuthConfig(overrides?)
Creates server-side authentication configuration.
<AuthProvider config={authConfig}>
Provides authentication context to your application.
// app/api/auth/login/route.ts
import { createGFTDAuth, createServerAuthConfig } from '@gftdcojp/auth'
const authConfig = createServerAuthConfig()
const auth = createGFTDAuth(authConfig)
export async function POST(request: Request) {
const { idToken } = await request.json()
const result = await auth.handleLogin({ idToken })
if (result.success) {
// Set session cookie
const response = NextResponse.json({ user: result.user })
response.cookies.set('session', result.accessToken!)
return response
}
return NextResponse.json({ error: result.error }, { status: 401 })
}
// middleware.ts
import { createAuthMiddleware, createServerAuthConfig } from '@gftdcojp/auth'
const authConfig = createServerAuthConfig()
const middleware = createAuthMiddleware({
authConfig,
publicPaths: ['/', '/signin', '/api/auth/login']
})
export default middleware
The package requires the following Firebase environment variables:
FIREBASE_PROJECT_ID
- Your Firebase project IDFIREBASE_CLIENT_EMAIL
- Firebase service account emailFIREBASE_PRIVATE_KEY
- Firebase service account private keyMIT © GFTD Co., Ltd.
This package supports secure communication between microservices using JWT tokens.
The auth service provides a JWKS endpoint for public key distribution:
GET /.well-known/jwks
This endpoint returns the public keys needed for JWT verification across all microservices.
Generate short-lived JWT tokens for secure inter-service communication:
import { createGFTDAuth, createServerAuthConfig } from '@gftdcojp/auth'
const config = createServerAuthConfig()
const auth = createGFTDAuth(config)
// Generate internal service token
const internalToken = await auth.createInternalServiceToken(
userId,
sessionId,
'https://target-service.com',
['read:orders', 'write:orders']
)
Microservices can verify internal JWT tokens using the JWKS endpoint:
// Verify internal service token
const userProfile = await auth.verifyInternalServiceToken(
token,
'https://my-service.com'
)
if (userProfile) {
// Token is valid - proceed with user context
console.log('User:', userProfile.sub)
console.log('Permissions:', userProfile.permissions)
}
1. User authenticates with Firebase
2. API Gateway (@100_api) creates internal JWT + Access Token
3. JWT sent to downstream services with Bearer header
4. Services verify JWT using JWKS endpoint
5. Services process request with authenticated user context
This ensures secure, decentralized microservice communication while maintaining user authentication context.
The API Gateway automatically creates internal JWT tokens during login:
// apps/100_api/src/app/api/auth/login/route.ts
import { getTokenService } from '../../../../../packages/030_core/src/server/token-service'
const tokenService = getTokenService()
const internalToken = await tokenService.createInternalServiceToken(
userId, sessionId, 'https://target-service.com', permissions
)
// Return both access token and internal service token
return { success: true, accessToken, internalServiceToken, user }
Use the microservice client for secure service-to-service communication:
// apps/100_api/src/lib/microservice-client.ts
import { getMicroserviceClient } from '@/lib/microservice-client'
const client = getMicroserviceClient()
const response = await client.callService(
'https://orders.gftd.ai',
'/api/orders',
'GET',
null,
userId,
sessionId,
['read:orders']
)
Microservices verify JWT tokens using the middleware:
// Any microservice endpoint
import { createMicroserviceAuthMiddleware, getAuthenticatedUser } from '@gftdcojp/auth/middleware'
const microserviceAuth = createMicroserviceAuthMiddleware({
expectedAudience: 'https://your-service.com',
requiredPermissions: ['read:orders'],
publicPaths: ['/health'], // Optional public endpoints
})
export async function GET(request: NextRequest) {
// Apply JWT authentication
const authResult = await microserviceAuth(request)
if (authResult.status !== 200) {
return authResult
}
// Get authenticated user
const user = getAuthenticatedUser(request)
// user: { userId, permissions, sessionId }
// Process authenticated request
return NextResponse.json({ data: 'authenticated response' })
}
// apps/100_api/src/app/api/orders/route.ts
import { createMicroserviceAuthMiddleware, getAuthenticatedUser } from '@gftdcojp/auth/middleware'
const auth = createMicroserviceAuthMiddleware({
expectedAudience: 'https://api.auth.gftd.ai',
requiredPermissions: ['read:orders'],
})
export async function GET(request: NextRequest) {
const authResult = await auth(request)
if (authResult.status !== 200) return authResult
const user = getAuthenticatedUser(request)
// Use user.userId, user.permissions for business logic
return NextResponse.json({
orders: await getUserOrders(user.userId),
user: { id: user.userId, permissions: user.permissions }
})
}
@100_api
)The following environment variables are required on the server responsible for signing and issuing JWTs.
# JWT Key Configuration (for the auth signing service)
AI_GFTD_JWT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
AI_GFTD_JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----\n"
AI_GFTD_JWT_KEY_ID="auth-key-1"
@200_user
, @120_admin
)With the dynamic JWKS flow, microservice clients no longer need to configure the public key directly. The verification library automatically fetches the latest keys from the authentication server's .well-known/jwks
endpoint.
You just need to ensure your service can reach the authentication server.
// Automatic environment detection
const jwksUrl = process.env.NODE_ENV === 'production'
? 'https://api.auth.gftd.ai/.well-known/jwks'
: 'http://localhost:3001/.well-known/jwks'
https://orders.gftd.ai
)// Always validate user permissions before creating internal tokens
const userPermissions = await getUserPermissions(userId)
if (!userPermissions.includes('required:permission')) {
throw new Error('Insufficient permissions')
}
// Implement rate limiting
const rateLimit = createRateLimiter({ windowMs: 60000, max: 100 })
app.use(rateLimit)
// Log security events
if (authResult.status !== 200) {
console.warn(`Authentication failed: ${request.url} from ${request.ip}`)
}
# Use encrypted environment variables
# Rotate keys every 90 days
# Use different keys for development/production
# Store keys in secure vaults, not in code
Implement comprehensive logging for:
// Add security headers to all responses
response.headers.set('X-Content-Type-Options', 'nosniff')
response.headers.set('X-Frame-Options', 'DENY')
response.headers.set('X-XSS-Protection', '1; mode=block')
response.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
For security issues, please email security@gftd.ai instead of creating public issues.
For general questions, please open an issue on GitHub.
FAQs
Zero-config authentication package for Next.js applications with Firebase integration
The npm package @gftdcojp/auth receives a total of 68 weekly downloads. As such, @gftdcojp/auth popularity was classified as not popular.
We found that @gftdcojp/auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.