Skip to content

Commit

Permalink
fix: error handling in callback
Browse files Browse the repository at this point in the history
Catch error from oicd call.
  • Loading branch information
cgawron committed Mar 19, 2024
1 parent 9aa59c0 commit 40ea43f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,21 @@ app.get('/callback', async (req, res) => {
const host = req.headers['x-forwarded-host'] || req.headers.host;
const prefix = req.headers['x-forwarded-prefix'] || '';

const tokenSet = await client.callback(REDIRECT_URI, params, { code_verifier: client.code_verifier });

console.log('tokenSet', tokenSet);
const user = jwt.decode(tokenSet.id_token);
const token = tokenSet.id_token;//jwt.sign({ user }, 'your_secret_key');

res.cookie('token', token);
const redirect_url = new URL(proto + '://' + host);
res.redirect(redirect_url);
client.callback(REDIRECT_URI, params, { code_verifier: client.code_verifier })
.then(tokenSet => {

console.log('tokenSet', tokenSet);
const user = jwt.decode(tokenSet.id_token);
const token = tokenSet.id_token;//jwt.sign({ user }, 'your_secret_key');

res.cookie('token', token);
const redirect_url = new URL(proto + '://' + host);
res.redirect(redirect_url);
})
.catch(err => {
console.log('error', err);
res.status(500).send('Error: ' + err);
});
});

app.get('/dashboard', (req, res) => {
Expand Down

0 comments on commit 40ea43f

Please sign in to comment.