rgz
rgz
CCConvex Community
Created by rgz on 8/20/2024 in #support-community
Using orCreateOrUpdate user in callback
Two problems here: 1. How can I get the tokenIdentity when creating a user, I need to get authSessionsId but I keep getting null. my approach was ${url}/${userId}/${tokenId} 2. I keep getting a 302 error but everything is still working correctly. GET /api/auth/signin/* 302 GET /api/auth/callback/* 302 This is the callback url I added on google: https://my-stuff-123.convex.site/api/auth/callback/google
callbacks: {
async createOrUpdateUser(ctx, args) {
let userId: Id<"users">;
const profile = args.profile as ExtendedProfile;
const provider = args.provider;

const existingUser = await ctx.db.query("users")
.filter((q) => q.eq(q.field("email"), args.profile.email))
.first();

if (existingUser) {
userId = existingUser._id as Id<"users">;

await ctx.db.patch<Id<"users">>(existingUser._id, {
providers: [...existingUser.providers, provider.id],
});

} else {
const newUser = await ctx.db.insert("users", {
email: profile?.email,
emailVerified: true,
emailVerificationTime: new Date().getTime(),
name: profile?.name,
firstName: profile?.given_name,
lastName: profile?.family_name,
image: profile?.image,
isOnboardingComplete: false,
orgIds: [],
providers: [provider.id],
tokenIdentifier: "",
});

userId = newUser as Id<"users">;
}

return userId;
},
},
callbacks: {
async createOrUpdateUser(ctx, args) {
let userId: Id<"users">;
const profile = args.profile as ExtendedProfile;
const provider = args.provider;

const existingUser = await ctx.db.query("users")
.filter((q) => q.eq(q.field("email"), args.profile.email))
.first();

if (existingUser) {
userId = existingUser._id as Id<"users">;

await ctx.db.patch<Id<"users">>(existingUser._id, {
providers: [...existingUser.providers, provider.id],
});

} else {
const newUser = await ctx.db.insert("users", {
email: profile?.email,
emailVerified: true,
emailVerificationTime: new Date().getTime(),
name: profile?.name,
firstName: profile?.given_name,
lastName: profile?.family_name,
image: profile?.image,
isOnboardingComplete: false,
orgIds: [],
providers: [provider.id],
tokenIdentifier: "",
});

userId = newUser as Id<"users">;
}

return userId;
},
},
8 replies
CCConvex Community
Created by rgz on 8/18/2024 in #support-community
Is there a way to store an _id to snapshot name via api?
I'm wanting to make a list where organizations can download their own data. Is there a way to customize a snapshot export name and call the export snapshot via api?
10 replies
CCConvex Community
Created by rgz on 8/17/2024 in #support-community
ConvexAuth error after prod on vercel
GET /api/auth/signin/* 302
GET /api/auth/callback/* 302
GET /api/auth/signin/* 302
GET /api/auth/callback/* 302
When using Convex Auth with google it works great on localhost but when I upload to vercel, I keep getting 302 with signin and callback.
2 replies
CCConvex Community
Created by rgz on 8/14/2024 in #support-community
Customizing default Schema after OAuth login
I'm trying to use the default schema and just update it with a few items: I updated my schema with a new users table and added two fields at the end:
...authTables,
users: defineTable({
email: v.optional(v.string()),
emailVerificationTime: v.optional(v.float64()),
image: v.optional(v.string()),
isAnonymous: v.optional(v.boolean()),
name: v.optional(v.string()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.float64()),
isOnboardingComplete: v.optional(v.boolean()),
orgIds: v.optional(v.array(v.object({
id: v.id("organization"),
role: v.union(v.literal("org:admin"), v.literal("org:member"))
}))),
})
.index("by_email", ["email"])
.index("by_phone", ["phone"]),
...authTables,
users: defineTable({
email: v.optional(v.string()),
emailVerificationTime: v.optional(v.float64()),
image: v.optional(v.string()),
isAnonymous: v.optional(v.boolean()),
name: v.optional(v.string()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.float64()),
isOnboardingComplete: v.optional(v.boolean()),
orgIds: v.optional(v.array(v.object({
id: v.id("organization"),
role: v.union(v.literal("org:admin"), v.literal("org:member"))
}))),
})
.index("by_email", ["email"])
.index("by_phone", ["phone"]),
In the auth I used the createOrUpdateUser callback in auth.ts to create the user:
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
GitHub,
Google,
ResendOTP,
Password,
Password({ id: "password-with-reset", reset: ResendOTPPasswordReset }),
Password({
id: "password-code",
reset: ResendOTPPasswordReset,
verify: ResendOTP,
}),
Password({ id: "password-link", verify: Resend }),
],
callbacks: {
async createOrUpdateUser(ctx, args) {
if (args.existingUserId) {
return args.existingUserId;
}

return ctx.db.insert("users", {
email: args.profile.email,
emailVerified: args.profile.emailVerified,
name: args.profile.name,
phone: args.profile.phone,
phoneVerified: args.profile.phoneVerified,
isOnboardingComplete: false,
orgIds: [],
});
},
},
});
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
GitHub,
Google,
ResendOTP,
Password,
Password({ id: "password-with-reset", reset: ResendOTPPasswordReset }),
Password({
id: "password-code",
reset: ResendOTPPasswordReset,
verify: ResendOTP,
}),
Password({ id: "password-link", verify: Resend }),
],
callbacks: {
async createOrUpdateUser(ctx, args) {
if (args.existingUserId) {
return args.existingUserId;
}

return ctx.db.insert("users", {
email: args.profile.email,
emailVerified: args.profile.emailVerified,
name: args.profile.name,
phone: args.profile.phone,
phoneVerified: args.profile.phoneVerified,
isOnboardingComplete: false,
orgIds: [],
});
},
},
});
5 replies
CCConvex Community
Created by rgz on 8/14/2024 in #support-community
Having some issues with getting user response ConvexAuth
No description
14 replies