refactor base auth
This commit is contained in:
@@ -4,21 +4,12 @@ import { components } from "./_generated/api";
|
||||
import { type DataModel } from "./_generated/dataModel";
|
||||
import { query } from "./_generated/server";
|
||||
import { betterAuth } from "better-auth";
|
||||
// import authSchema from "./betterAuth/schema";
|
||||
|
||||
const siteUrl = process.env.SITE_URL!;
|
||||
|
||||
// The component client has methods needed for integrating Convex with Better Auth,
|
||||
// as well as helper methods for general use.
|
||||
export const authComponent = createClient<DataModel>(components.betterAuth);
|
||||
// export const authComponent = createClient<DataModel, typeof authSchema>(
|
||||
// components.betterAuth,
|
||||
// {
|
||||
// local: {
|
||||
// schema: authSchema,
|
||||
// },
|
||||
// }
|
||||
// );
|
||||
|
||||
export const createAuth = (
|
||||
ctx: GenericCtx<DataModel>,
|
||||
@@ -49,6 +40,18 @@ export const createAuth = (
|
||||
export const getCurrentUser = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
return authComponent.getAuthUser(ctx);
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx as any);
|
||||
if (!authUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await ctx.db
|
||||
.query("usuarios")
|
||||
.withIndex("authId", (q) => q.eq("authId", authUser._id))
|
||||
.unique();
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
return user;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user