Kevin
Kevin
CCConvex Community
Created by Kevin on 8/29/2024 in #support-community
[Convex Auth] Middleware on Nextjs
Following https://labs.convex.dev/auth/authz/nextjs After using signIn from useAuthActions by Email OTP (from resend),
const { signIn } = useAuthActions()

await signIn("resend-otp", { email , code})
const { signIn } = useAuthActions()

await signIn("resend-otp", { email , code})
on client side,
const { isAuthenticated, isLoading } = useConvexAuth()
const { isAuthenticated, isLoading } = useConvexAuth()
I see isAuthenticated = true however, on middleware,
import {
convexAuthNextjsMiddleware,
createRouteMatcher,
isAuthenticatedNextjs,
nextjsMiddlewareRedirect,
} from "@convex-dev/auth/nextjs/server";

const isSignInPage = createRouteMatcher(["/signin"]);
const isProtectedRoute = createRouteMatcher(["/product(.*)"]);

export default convexAuthNextjsMiddleware((request) => {
if (isSignInPage(request) && isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/product");
}
if (isProtectedRoute(request) && !isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/signin");
}
});

export const config = {
// The following matcher runs middleware on all routes
// except static assets.
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
import {
convexAuthNextjsMiddleware,
createRouteMatcher,
isAuthenticatedNextjs,
nextjsMiddlewareRedirect,
} from "@convex-dev/auth/nextjs/server";

const isSignInPage = createRouteMatcher(["/signin"]);
const isProtectedRoute = createRouteMatcher(["/product(.*)"]);

export default convexAuthNextjsMiddleware((request) => {
if (isSignInPage(request) && isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/product");
}
if (isProtectedRoute(request) && !isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/signin");
}
});

export const config = {
// The following matcher runs middleware on all routes
// except static assets.
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
isAuthenticatedNextjs() is always false can you guys let me know how to debug this? There is no error shown from console or terminal?
11 replies
CCConvex Community
Created by Kevin on 8/26/2024 in #support-community
"Could not verify token claim" on React Native
Hi guys, I am trying to replace Clerk Auth with Convex Auth using in react native (with expo) I am testing locally, after trying to verifying code via email I got this issue Failed to authenticate: "Could not verify token claim", check your server auth config "check your server auth config" What exactly do I need to check? auth.ts
import Apple from "@auth/core/providers/apple";
import Google from "@auth/core/providers/google";
import Resend from "@auth/core/providers/resend";
import { Anonymous } from "@convex-dev/auth/providers/Anonymous";
import { convexAuth } from "@convex-dev/auth/server";

import { env } from "./env";
import { ResendOTP } from "./lib/auth/otp/email/resend_otp";

export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Apple,
Google,
Anonymous,
Resend({
apiKey: env.RESEND_API_KEY,
from: env.RESEND_FROM_ADDRESS,
}),
ResendOTP,
],
});
import Apple from "@auth/core/providers/apple";
import Google from "@auth/core/providers/google";
import Resend from "@auth/core/providers/resend";
import { Anonymous } from "@convex-dev/auth/providers/Anonymous";
import { convexAuth } from "@convex-dev/auth/server";

import { env } from "./env";
import { ResendOTP } from "./lib/auth/otp/email/resend_otp";

export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Apple,
Google,
Anonymous,
Resend({
apiKey: env.RESEND_API_KEY,
from: env.RESEND_FROM_ADDRESS,
}),
ResendOTP,
],
});
Note: I can see user is inserted in users table with this data
{
email: "yolo09@mailinator.com",
emailVerificationTime: 1724679714774,
}
{
email: "yolo09@mailinator.com",
emailVerificationTime: 1724679714774,
}
65 replies