Issue
generateToken(request, reply) {
let token = //JWT token generated
request.headers.Authorization = token;
//also tried
request.response.header('token' , token);
reply.redirect('/newPath')
}
The new path does not have these headers. I also tried to set the token from 'onPreResponse' stage but same result. I am using hapi version 16.
Solution
Added it as a search param to the redirect URL. The search params won't be sent to the server when requesting a URL, so the token shouldn't end up in any logs.
res.redirect(`http://appServer:5001/?key=value#jwt=${token}`)
const token = (new URL(document.location)).searchParams.get('jwt');
Answered By - eagerToLearn
Answer Checked By - David Goodson (JavaFixing Volunteer)