Skip to content

Commit 33f16fe

Browse files
committed
feat: code review updates
1 parent b365c2f commit 33f16fe

File tree

10 files changed

+301
-177
lines changed

10 files changed

+301
-177
lines changed

asynchronous-authorization/langchain-next-js/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ AUTH0_CLIENT_SECRET="{yourClientSecret}"
1111
# Database configuration
1212
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ai_documents_db"
1313

14+
# Auth0 FGA
15+
FGA_STORE_ID=<your-fga-store-id>
16+
FGA_CLIENT_ID=<your-fga-store-client-id>
17+
FGA_CLIENT_SECRET=<your-fga-store-client-secret>
18+
FGA_API_URL=https://api.xxx.fga.dev
19+
FGA_API_AUDIENCE=https://api.xxx.fga.dev/
20+
FGA_API_TOKEN_ISSUER=auth.fga.dev
21+
1422
# LANGGRAPH
1523
LANGGRAPH_API_URL=http://localhost:54367
1624
# Optional: For Tracing with LangSmith

asynchronous-authorization/langchain-next-js/bun.lock

Lines changed: 231 additions & 141 deletions
Large diffs are not rendered by default.

asynchronous-authorization/langchain-next-js/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"lucide-react": "^0.543.0",
5050
"marked": "^16.2.1",
5151
"nanoid": "^5.1.5",
52-
"next": "^15.5.2",
52+
"next": "^15.5.4",
5353
"next-themes": "^0.4.6",
5454
"nuqs": "^2.6.0",
5555
"pdf-parse": "^1.1.1",
@@ -74,6 +74,8 @@
7474
"@types/pdf-parse": "^1.1.5",
7575
"@types/react": "^19.1.12",
7676
"@types/react-dom": "^19.1.9",
77+
"@typescript-eslint/eslint-plugin": "^8.45.0",
78+
"@typescript-eslint/parser": "^8.45.0",
7779
"autoprefixer": "^10.4.21",
7880
"dotenv": "^16.4.5",
7981
"drizzle-kit": "^0.31.4",
@@ -82,7 +84,7 @@
8284
"npm-run-all": "^4.1.5",
8385
"postcss": "^8.5.6",
8486
"prettier": "^3.6.2",
85-
"@tailwindcss/postcss": "^4.1.13",
87+
"tailwindcss": "^3.4.17",
8688
"tsx": "^4.20.5",
8789
"typescript": "^5.9.2"
8890
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const config = {
22
plugins: {
3-
"@tailwindcss/postcss": {},
3+
tailwindcss: {},
4+
autoprefixer: {},
45
},
56
};
67
export default config;

asynchronous-authorization/langchain-next-js/src/app/globals.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
@import "tailwindcss";
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
24

35
@layer base {
46
:root {

asynchronous-authorization/langchain-next-js/src/lib/agent.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import { shopOnlineTool } from './tools/shop-online';
88

99
const date = new Date().toISOString();
1010

11-
const AGENT_SYSTEM_TEMPLATE = `You are a personal assistant named Assistant0. You are a helpful assistant that can answer questions and help with tasks. You have access to a set of tools, use the tools as needed to answer the user's question. Render the email body as a markdown block, do not wrap it in code blocks. Today is ${date}.`;
11+
const AGENT_SYSTEM_TEMPLATE = `You are a personal assistant named Assistant0. You are a helpful assistant that can answer questions and help with tasks.
12+
13+
You have access to a set of tools. When using tools, you MUST provide valid JSON arguments. Always format tool call arguments as proper JSON objects.
14+
15+
For example, when calling shop_online tool, format like this:
16+
{"product": "iPhone", "qty": 1, "priceLimit": 1000}
17+
18+
Use the tools as needed to answer the user's question. Render the email body as a markdown block, do not wrap it in code blocks. Today is ${date}.`;
1219

1320
const llm = new ChatOpenAI({
1421
model: 'gpt-4o',

asynchronous-authorization/langchain-next-js/src/lib/auth0-ai.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export const withAsyncAuthorization = auth0AI.withAsyncUserConfirmation({
1212
scopes: ['openid', 'product:buy'], // add any scopes you want to use with your API
1313
audience: process.env['SHOP_API_AUDIENCE']!,
1414

15+
/**
16+
* Note: Setting a requested expiry greater than 300 (seconds) will force email verification
17+
* instead of using the push notification flow.
18+
*/
19+
// requestedExpiry: 301,
1520
/**
1621
* When this flag is set to `block`, the execution of the tool awaits
1722
* until the user approves or rejects the request.
Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
import { buildOpenFgaClient } from '@auth0/ai';
22

3-
export const fgaClient = buildOpenFgaClient();
3+
// Initialize FGA client only if credentials are provided
4+
let fgaClient: ReturnType<typeof buildOpenFgaClient> | null = null;
45

5-
export const addRelation = async (userEmail: string, documentId: string, relation = 'owner') =>
6-
fgaClient.write({
6+
try {
7+
// Check if FGA credentials are available
8+
if (process.env.FGA_CLIENT_ID && process.env.FGA_STORE_ID) {
9+
fgaClient = buildOpenFgaClient();
10+
}
11+
} catch (error) {
12+
console.warn('FGA client initialization failed. FGA features will be disabled.', error);
13+
}
14+
15+
export { fgaClient };
16+
17+
export const addRelation = async (userEmail: string, documentId: string, relation = 'owner') => {
18+
if (!fgaClient) {
19+
console.warn('FGA client not available. Skipping relation addition.');
20+
return;
21+
}
22+
23+
return fgaClient.write({
724
writes: [{ user: `user:${userEmail}`, relation, object: `doc:${documentId}` }],
825
});
26+
};
927

10-
export const deleteRelation = async (userEmail: string, documentId: string, relation = 'owner') =>
11-
fgaClient.write({
28+
export const deleteRelation = async (userEmail: string, documentId: string, relation = 'owner') => {
29+
if (!fgaClient) {
30+
console.warn('FGA client not available. Skipping relation deletion.');
31+
return;
32+
}
33+
34+
return fgaClient.write({
1235
deletes: [{ user: `user:${userEmail}`, relation, object: `doc:${documentId}` }],
1336
});
37+
};
Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
1-
import { NextRequest, NextResponse } from "next/server";
2-
import { auth0 } from "./lib/auth0";
1+
import type { NextRequest } from "next/server"
32

4-
const APP_SESSION_COOKIE = "appSession";
3+
import { auth0 } from "./lib/auth0"
54

65
export async function middleware(request: NextRequest) {
7-
const { pathname } = request.nextUrl;
8-
9-
if (pathname.startsWith("/auth")) {
10-
return auth0.middleware(request);
11-
}
12-
13-
try {
14-
const session = await auth0.getSession(request);
15-
if (!session) {
16-
return NextResponse.redirect(new URL("/auth/login", request.url));
17-
}
18-
return NextResponse.next();
19-
} catch {
20-
const redirect = NextResponse.redirect(new URL("/auth/login", request.url));
21-
redirect.cookies.set(APP_SESSION_COOKIE, "", {
22-
path: "/",
23-
httpOnly: true,
24-
maxAge: 0,
25-
});
26-
return redirect;
27-
}
6+
return await auth0.middleware(request);
287
}
298

309
export const config = {
3110
matcher: [
32-
"/((?!_next/static|_next/image|images|favicon\\.(?:ico|png)|sitemap\\.xml|robots\\.txt|$).*)",
11+
/*
12+
* Match all request paths except for the ones starting with:
13+
* - _next/static (static files)
14+
* - _next/image (image optimization files)
15+
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
16+
*/
17+
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
3318
],
34-
};
19+
}

0 commit comments

Comments
 (0)