gioru
gioru
CCConvex Community
Created by gioru on 8/27/2024 in #support-community
Need help with handling Convex Auth signIn errors in prod
Tried the api route way but had no success since useAuthActions can be called only inside react components. Tried the signIn convex server function too but wasn't enough to make the signin flow work. 🥲
http.route({
path: '/sign-in',
method: 'POST',
handler: httpAction(async (ctx, request) => {
const { provider, params } = await request.json();
const { signIn } = useAuthActions()

try {
const signinResult = await signIn(provider, params)

return new Response(JSON.stringify(signinResult), {
status: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
}
})
} catch (error: any) {
return new Response(error, { status: 400 })
}
})
})

http.route({
path: '/sign-in',
method: 'OPTIONS',
handler: httpAction(async (ctx, request) => {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
}
})
})
})
http.route({
path: '/sign-in',
method: 'POST',
handler: httpAction(async (ctx, request) => {
const { provider, params } = await request.json();
const { signIn } = useAuthActions()

try {
const signinResult = await signIn(provider, params)

return new Response(JSON.stringify(signinResult), {
status: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
}
})
} catch (error: any) {
return new Response(error, { status: 400 })
}
})
})

http.route({
path: '/sign-in',
method: 'OPTIONS',
handler: httpAction(async (ctx, request) => {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
}
})
})
})
30 replies
CCConvex Community
Created by gioru on 7/26/2024 in #support-community
NODE_ENV always equates to 'development'
Can I ask you one more thing? Is it normal behaviour that I can't destructure single item queries?
export const getOne = internalQuery({
args: {
userId: v.id("users")
},
handler: async (ctx, { userId }) => {
const item = await ctx.db
.query("subscriptions")
.withIndex("byUserId", q => q.eq("userId", userId))
.unique()
return item
}
})
export const getOne = internalQuery({
args: {
userId: v.id("users")
},
handler: async (ctx, { userId }) => {
const item = await ctx.db
.query("subscriptions")
.withIndex("byUserId", q => q.eq("userId", userId))
.unique()
return item
}
})
const { _id } = await ctx.runQuery(internal.subscriptions.index.getOne, { userId })
const { _id } = await ctx.runQuery(internal.subscriptions.index.getOne, { userId })
Gives me type error: "Property '_id' does not exist on type '{ _id: Id<"subscriptions">; _creationTime: number; ...."
7 replies
CCConvex Community
Created by gioru on 7/26/2024 in #support-community
NODE_ENV always equates to 'development'
Thanks for the answer Michal, yes was wondering if it was automatically handled by you but ok the cause must be somewhere else, maybe nextjs's. Temporarily solved by calling the variable "CONVEX_ENV"; needed to distinguish the environments for stripe checkouts.
7 replies