General question: For a larger corporate application we need to separate the user authentication part from the user application data. Let’s say we are using MongoDB for the authentication and MySQL for other user data. How can the user IDs in both systems be mapped? So, after successful login the user should see his/her information. No 3rd-party accounts like Google or Facebook should be used.
4
Create a callback route after successfull authentication, then use that data to query your MySQL database.
export const callback = async (
req: Request,
res: Response,
next: NextFunction
) => {
async function callback(userDetails: { username: string }) {
// find user in mongodb
let user = await User.findOne({ username: userDetails.username });
if (!user) {
user = // await create user in mysql
}
return user;
}
};
I recommend looking into passport, if you haven’t already.
1