- Register SITE_URL, NATIVE_APP_URL, CONVEX_SITE_URL, FLUE_DB_TOKEN in convex.config.ts so the generated server.js exposes a typed env object. - Rewrite auth.ts to consume @code/env/convex and tighten the getCurrentUser handler. - Refresh the backend README to describe the control-plane role and generated-file policy.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { expo } from "@better-auth/expo";
|
|
import { env } from "@code/env/convex";
|
|
import { createClient } from "@convex-dev/better-auth";
|
|
import type { GenericCtx } from "@convex-dev/better-auth";
|
|
import { convex, crossDomain } from "@convex-dev/better-auth/plugins";
|
|
import { betterAuth } from "better-auth/minimal";
|
|
|
|
import { components } from "./_generated/api";
|
|
import type { DataModel } from "./_generated/dataModel";
|
|
import { query } from "./_generated/server";
|
|
import authConfig from "./auth.config";
|
|
|
|
const siteUrl = env.SITE_URL;
|
|
const nativeAppUrl = env.NATIVE_APP_URL ?? "code://";
|
|
|
|
export const authComponent = createClient<DataModel>(components.betterAuth);
|
|
|
|
const createAuth = (ctx: GenericCtx<DataModel>) =>
|
|
betterAuth({
|
|
baseURL: env.CONVEX_SITE_URL,
|
|
database: authComponent.adapter(ctx),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
requireEmailVerification: false,
|
|
},
|
|
plugins: [
|
|
expo(),
|
|
crossDomain({ siteUrl }),
|
|
convex({
|
|
authConfig,
|
|
jwksRotateOnTokenGenerationError: true,
|
|
}),
|
|
],
|
|
trustedOrigins: [siteUrl, nativeAppUrl, "exp://"],
|
|
});
|
|
|
|
export { createAuth };
|
|
|
|
export const getCurrentUser = query({
|
|
args: {},
|
|
handler: (ctx) => authComponent.safeGetAuthUser(ctx),
|
|
});
|