Skip to content

Commit

Permalink
🐛 fix: fix onboard and auth for community version (#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Jun 17, 2024
1 parent e815c47 commit b02020d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clerkMiddleware } from '@clerk/nextjs/server';
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
import { NextResponse } from 'next/server';

import { authEnv } from '@/config/auth';
Expand All @@ -13,6 +13,7 @@ export const config = {
// include the /
'/',
'/chat(.*)',
'/settings(.*)',
// ↓ cloud ↓
],
};
Expand Down Expand Up @@ -42,8 +43,18 @@ const nextAuthMiddleware = auth((req) => {
});
});

const isProtectedRoute = createRouteMatcher([
'/settings(.*)',
// ↓ cloud ↓
]);

export default authEnv.NEXT_PUBLIC_ENABLE_CLERK_AUTH
? clerkMiddleware()
? clerkMiddleware(
(auth, req) => {
if (isProtectedRoute(req)) auth().protect();
},
{ signInUrl: '/login', signUpUrl: '/signup' },
)
: authEnv.NEXT_PUBLIC_ENABLE_NEXT_AUTH
? nextAuthMiddleware
: defaultMiddleware;
3 changes: 2 additions & 1 deletion src/server/routers/lambda/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const userRouter = router({
// 有消息,或者创建过助手,则认为有 conversation
hasConversation: messageCount > 0 || sessionCount > 1,

isOnboard: state.isOnboarded || false,
// always return true for community version
isOnboard: state.isOnboarded || true,
preference: state.preference as UserPreference,
settings: state.settings,
userId: ctx.userId,
Expand Down

0 comments on commit b02020d

Please sign in to comment.