Secure authentication with JWT for Google Antigravity IDE
# JWT Authentication Complete Guide for Google Antigravity
Master JSON Web Token authentication in Google Antigravity IDE.
## Configuration
```typescript
// .antigravity/jwt.ts
export const jwtConfig = {
accessTokenExpiry: "15m",
refreshTokenExpiry: "7d",
algorithm: "RS256"
};
```
## Token Generation
```typescript
import jwt from "jsonwebtoken";
interface TokenPayload {
userId: string;
email: string;
role: string;
}
export function generateTokenPair(payload: TokenPayload) {
const accessToken = jwt.sign(payload, process.env.ACCESS_SECRET!, {
expiresIn: "15m"
});
const refreshToken = jwt.sign(
{ userId: payload.userId },
process.env.REFRESH_SECRET!,
{ expiresIn: "7d" }
);
return { accessToken, refreshToken };
}
export function verifyAccessToken(token: string): TokenPayload {
return jwt.verify(token, process.env.ACCESS_SECRET!) as TokenPayload;
}
```
## Middleware
```typescript
import { NextRequest, NextResponse } from "next/server";
export async function authMiddleware(request: NextRequest) {
const authHeader = request.headers.get("authorization");
if (!authHeader?.startsWith("Bearer ")) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
try {
const token = authHeader.split(" ")[1];
const payload = verifyAccessToken(token);
return NextResponse.next();
} catch {
return NextResponse.json({ error: "Invalid token" }, { status: 401 });
}
}
```
## Best Practices
1. **Short access token expiry**
2. **Rotate refresh tokens**
3. **Use HttpOnly cookies**
Google Antigravity IDE provides JWT scaffolding.This Authentication prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their authentication implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For Authentication projects, consider mentioning your framework version, coding style, and any specific libraries you're using.