Working on a PNPM monorepo containing three workspaces: web, mobile and server (convex server)
Server contains the following better auth configuration:
const siteUrl = "http://mattam.local:5174";
export const createAuth = (ctx: GenericCtx) =>
betterAuth({
trustedOrigins: ["mattam://", siteUrl],
database: convexAdapter(ctx, betterAuthComponent),
emailAndPassword: {enabled: true, requireEmailVerification: false,},
plugins: [ convex(), expo(),
// Apparently, this crossDomain plugin redirects me to siteUrl to accomplish something.
// Much unwanted behavior on mobile, since I'm not using social login.
crossDomain({
siteUrl,
}),
],
});
Since mobile doesn't require CORS protection, I omit the crossDomain plugin when creating the client:
import { createAuthClient } from "better-auth/react";
import { convexClient } from "@convex-dev/better-auth/client/plugins";
import * as SecureStore from "expo-secure-store";
import { expoClient } from "@better-auth/expo/client";
export const authClient = createAuthClient({
baseURL: process.env.EXPO_PUBLIC_CONVEX_SITE_URL,
plugins: [
expoClient({ scheme: "mattam", storagePrefix: "mattam", storage: SecureStore }),
convexClient(),
],
});
Web (react) still uses it normally:
import { createAuthClient } from "better-auth/react";
import { convexClient, crossDomainClient, } from "@convex-dev/better-auth/client/plugins";
export const authClient = createAuthClient({
baseURL: import.meta.env.VITE_CONVEX_SITE_URL,
plugins: [ convexClient(), crossDomainClient() ],
});
Problem arises: crossDomain causees redirection when request is initiated from mobile (with faulty redirection since cookies are in the app!)
Is there a way to disable this crossDomain behaviour if request is from mobile app?