``onHandleEvent: async (context) => { if...
# general
m
``onHandleEvent: async (context) => { if (context.action === "SESSION_ALREADY_EXISTS") { // TODO: } else if (context.action === "PASSWORDLESS_RESTART_FLOW") { // TODO: } else if (context.action === "PASSWORDLESS_CODE_SENT") { // TODO: } else { let { id, email } = context.user; if (context.action === "SUCCESS") { if (context.isNewUser) { // Sign up createUser(id, email); } else { // Sign in updateUser(id, email); } } } },``
r
hey @Maxime R are you redirecting the user to a different page before waiting for the reply from the API?
i don't know
r
hmm
the flow seems to work fine. Just that your API is failing
when the createUser API is called, what are the request and response headers?
m
`` // Next.js API route support: https://nextjs.org/docs/api-routes/introduction import { PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); export default async (req, res) => { const { path } = req.query; if (path == "create") { // create user const { superTokenId, email } = req.body; try { const result = await prisma.user.create({ data: { superTokenId, email, wallets: ["0xbdfa4f4492dd7b7cf211209c4791af8d52bf5c50"], }, }); res.status(200).json(result); } catch (err) { res.status(403).json({ err: "Error while adding new user." }); } } ``
r
no i mean what are the headers shown in the network tab?
m
nothing
r
hmm
im not sure
m
POST /api/auth/user/create undefined Host: localhost:3000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/110.0 Accept: application/json, text/plain, / Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate, br Referer: http://localhost:3000/auth/verify/?rid=passwordless&preAuthSessionId=r_4aOjf4q9L-YwzF-Azw2lI_HM56SEdZ8stuZyeh0J8%3D Content-Type: application/json rid: anti-csrf Content-Length: 37
r
i think the issue is that it's being redirected too soon
if you want to create a user, then you should do that in the sign up override on the backend
and not on the frontend via an API call
see our docs for post sign up action
m
hum
do you have an URL ?
m
it's super complicated for me
Okay after a good night's sleep I figured it out and I did it, I made calls to an api (createuser) via axios in frontendconfig.js at the context.isnewuser level I removed this part and I took back my api logic to create my user directly in backendconfig.js at the equivalent level
r
makes sense
m
``... consumeCodePOST: async (input) => { console.log('consumecode POST'); if (originalImplementation.consumeCodePOST === undefined) { throw Error("Should never come here"); } // First we call the original implementation of consumeCodePOST. let response = await originalImplementation.consumeCodePOST(input); // Post sign up response, we check if it was successful if (response.status === "OK") { let { id, email } = response.user; //console.log(response,'response'); if (response.createdNewUser) { // TODO: post sign up logic console.log('create new user prisma / backend'); try { const result = await prisma.user.create({ ....``
@rp thanks !
r
awesome! :))
m
😉