Sronds
Sronds
CCConvex Community
Created by THEO on 12/16/2024 in #support-community
Clerk integration call functions infinitely - need help
thanks team, good work! ❤️❤️
12 replies
CCConvex Community
Created by THEO on 12/16/2024 in #support-community
Clerk integration call functions infinitely - need help
just ran into this bug myself! thanks
12 replies
CCConvex Community
Created by Eva on 9/1/2024 in #support-community
Deleting users with Convex Auth
if it helps anyone else, i wrote this function which works great.
export const deleteUser = userMutation({
args: {},
handler: async ({ ctx, userId }) => {
// delete all instances of the user from the database
console.log('Deleting user with id:', userId)

// authAccounts
const authAccount = await ctx.db
.query('authAccounts')
.withIndex('userIdAndProvider', (q) => q.eq('userId', userId))
.collect()

await Promise.all(
authAccount.map(async (account) => {
await ctx.db.delete(account._id)
})
)

const authSessions = await ctx.db
.query('authSessions')
.withIndex('userId', (q) => q.eq('userId', userId))
.collect()

// loop through all sessions and delete the associated refresh tokens in the authRefreshTokens table
await Promise.all(
authSessions.map(async (session) => {
const authRefreshTokens = await ctx.db
.query('authRefreshTokens')
.withIndex('sessionId', (q) => q.eq('sessionId', session._id))
.collect()

await Promise.all(
authRefreshTokens.map(async (token) => {
await ctx.db.delete(token._id)
})
)
})
)

// delete all sessions
await Promise.all(
authSessions.map(async (session) => {
await ctx.db.delete(session._id)
})
)

// MAKE SURE TO DELETE ANY OTHER USER DATA YOU'VE CREATED YOURSELF IN OTHER TABLES (messages, posts, etc...)

// delete user from the users table
return await ctx.db.delete(userId)
},
})
export const deleteUser = userMutation({
args: {},
handler: async ({ ctx, userId }) => {
// delete all instances of the user from the database
console.log('Deleting user with id:', userId)

// authAccounts
const authAccount = await ctx.db
.query('authAccounts')
.withIndex('userIdAndProvider', (q) => q.eq('userId', userId))
.collect()

await Promise.all(
authAccount.map(async (account) => {
await ctx.db.delete(account._id)
})
)

const authSessions = await ctx.db
.query('authSessions')
.withIndex('userId', (q) => q.eq('userId', userId))
.collect()

// loop through all sessions and delete the associated refresh tokens in the authRefreshTokens table
await Promise.all(
authSessions.map(async (session) => {
const authRefreshTokens = await ctx.db
.query('authRefreshTokens')
.withIndex('sessionId', (q) => q.eq('sessionId', session._id))
.collect()

await Promise.all(
authRefreshTokens.map(async (token) => {
await ctx.db.delete(token._id)
})
)
})
)

// delete all sessions
await Promise.all(
authSessions.map(async (session) => {
await ctx.db.delete(session._id)
})
)

// MAKE SURE TO DELETE ANY OTHER USER DATA YOU'VE CREATED YOURSELF IN OTHER TABLES (messages, posts, etc...)

// delete user from the users table
return await ctx.db.delete(userId)
},
})
if anyone is curious, this is my userMutation:
export const userMutation = customMutation(
mutation,
customCtx(async (ctx) => {
const userId = await getUserIdentity(ctx)
return { userId, ctx }
})
)
export const userMutation = customMutation(
mutation,
customCtx(async (ctx) => {
const userId = await getUserIdentity(ctx)
return { userId, ctx }
})
)
18 replies
CCConvex Community
Created by Web Dev Cody on 9/3/2024 in #support-community
Convex Auth Question
Thanks @Indy, appreciate you ❤️
9 replies
CCConvex Community
Created by Web Dev Cody on 9/3/2024 in #support-community
Convex Auth Question
which is then used here
const result = await openAuthSessionAsync(redirect!.toString(), redirectTo)
const result = await openAuthSessionAsync(redirect!.toString(), redirectTo)
9 replies
CCConvex Community
Created by Web Dev Cody on 9/3/2024 in #support-community
Convex Auth Question
looking at the code in signIn.js (@convex-dev/auth/dist/server/implmenetation/signIn.js) y'all are using
const redirect = new URL(requireEnv("CONVEX_SITE_URL") + `/api/auth/signin/${provider.id}`);
const redirect = new URL(requireEnv("CONVEX_SITE_URL") + `/api/auth/signin/${provider.id}`);
9 replies
CCConvex Community
Created by Web Dev Cody on 9/3/2024 in #support-community
Convex Auth Question
@Web Dev Cody @sshader i've tried to setup a custom domain but unfortunately google auth is not picking it up and only using original convex one. Any updates on this?
9 replies
CCConvex Community
Created by Sronds on 11/18/2024 in #support-community
help me setup a cronjob that loops through my entire user table and updates a number
managed to fix it by reading through this article https://stack.convex.dev/migrating-data-with-mutations specifically this piece of code
export const myMigrationBatch = internalMutation({
args: { cursor: v.union(v.string(), v.null()), numItems: v.number() },
handler: async (ctx, args) => {
const data = await ctx.db.query("mytable").paginate(args);
const { page, isDone, continueCursor } = data;
for (const doc of page) {
// modify doc
}
if (!isDone) await ctx.scheduler.runAfter(0, internal.example.myMigrationBatch, {
cursor: continueCursor,
numItems: args.numItems,
});
}
);
export const myMigrationBatch = internalMutation({
args: { cursor: v.union(v.string(), v.null()), numItems: v.number() },
handler: async (ctx, args) => {
const data = await ctx.db.query("mytable").paginate(args);
const { page, isDone, continueCursor } = data;
for (const doc of page) {
// modify doc
}
if (!isDone) await ctx.scheduler.runAfter(0, internal.example.myMigrationBatch, {
cursor: continueCursor,
numItems: args.numItems,
});
}
);
3 replies