fix: cache Convex JWT in server auth
This commit is contained in:
@@ -1,5 +1,30 @@
|
||||
import { convexBetterAuthNextJs } from "@convex-dev/better-auth/nextjs";
|
||||
|
||||
function getErrorText(error: unknown): string {
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
if (typeof error === "string") {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (error && typeof error === "object") {
|
||||
const { data, message } = error as { data?: unknown; message?: unknown };
|
||||
return [message, data]
|
||||
.filter((value): value is string => typeof value === "string")
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
function isConvexAuthError(error: unknown): boolean {
|
||||
return /\b(Unauthenticated|Unauthorized|Not authenticated)\b/i.test(
|
||||
getErrorText(error),
|
||||
);
|
||||
}
|
||||
|
||||
export const {
|
||||
handler,
|
||||
preloadAuthQuery,
|
||||
@@ -11,4 +36,8 @@ export const {
|
||||
} = convexBetterAuthNextJs({
|
||||
convexUrl: process.env.NEXT_PUBLIC_CONVEX_URL!,
|
||||
convexSiteUrl: process.env.NEXT_PUBLIC_CONVEX_SITE_URL!,
|
||||
jwtCache: {
|
||||
enabled: true,
|
||||
isAuthError: isConvexAuthError,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user