there are tons of questions with this issue, I read them all but did not see any similar issue. in my case "auth" is prepending. this is what i registered in the app settings as call back url
http://localhost:4500/auth/google/callback
this is passport.js configuration:
passport.use(
new GoogleStrategy.Strategy(
{
clientID: process.env.GOOGLE_CLIENT_ID!,// "!" is typescript
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
callbackURL: "auth/google/callback",
},
async (accessToken, refreshToken, profile, done) => {
const existingUser = await User.findOne({ googleId: profile.id });
if (existingUser) {
done(undefined, existingUser);
}
const user = await new User({ googleId: profile.id }).save();
done(undefined, user);
}
)
);
Here are the routes:
export const authRoutes = (app: Application) => {
//with passing "google" passport knows that it will use GoogleStrategy
app.get(
"/auth/google",
passport.authenticate("google", { scope: ["profile", "email"] })
);
app.get("/auth/google/callback", passport.authenticate("google"));
app.get("/auth/current_user", (req: Request, res: Response) => {
res.send(req.user);
});
app.get("/auth/logout", (req: Request, res: Response) => {
req.logout();
res.json({ user: req.user });
});
};
here is the error message:
Error 400: redirect_uri_mismatch The redirect URI in the request, http://localhost:4500/auth/auth/google/callback, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}
authparts ? - Dilshan