How do I redirect the user to another URL after login with the URL containing users email

I’m using the express-openid-connect SDK.

After a successful login , I would like to redirect the user to the URL localhost:3000/user/:email.

So basically , after a login , I will need to get the users email id and then redirect to the url
localhost:3000/user/:email

How do I implement this ?

Here’s an example

Install the required packages:
npm install express express-openid-connect

configuration according to your Auth0 :slight_smile:


const express = require('express');
const { auth } = require('express-openid-connect');

const app = express();

app.use(
  auth({
    issuerBaseURL: 'https://YOUR_AUTH0_DOMAIN',
    clientID: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    baseURL: 'http://localhost:3000', // Update with your app's base URL
    routes: {
      callback: '/callback',
    },
  })
);

Set up a route to handle the successful login and redirect the user:


app.get('/callback', (req, res) => {
  // Get the authenticated user's email
  const email = req.openid.user.email;

  // Redirect to the URL containing the user's email
  res.redirect(`/user/${encodeURIComponent(email)}`);
});

Set up a route to handle the redirected URL containing the user’s email:

app.get(‘/user/:email’, (req, res) => {
const email = req.params.email;

// Render the user’s email on the page
res.send(User email: ${email});
});

Then Start the server

app.listen(3000, () => {
  console.log('Server started on port 3000');
});

Try this.