Hi, I am using the nextjs-auth0 SDK.
How/where after login should I be checking if the user exists in my external DB, and to create the user in the external DB if they do not exist?
I attempted to use afterCallback, but am unsure how to make it work.
const afterCallback = async (req, res, session, state) => {
console.log("session info: ", session.user);
console.log("state info: ", state);
// check if user exists in a DB
const userExists = await client.query({ CUSTOMER_QUERY });
// if not, create user in postgres DB
return session;
};
export default handleAuth({
async login(req, res) {
try {
await handleLogin(req, res, {
returnTo: "/dashboard",
});
} catch (error) {
res.status(error.status || 400).end(error.message);
}
},
async callback(req, res) {
try {
await handleCallback(req, res, { afterCallback });
} catch (error) {
res.status(error.status || 500).end();
}
},
});