njs-examples icon indicating copy to clipboard operation
njs-examples copied to clipboard

Authorization Header Not Sent

Open AbdallahTarabish opened this issue 1 year ago • 0 comments

let reply = await r.subrequest('/auth' , {
         method: 'POST',
         body: JSON.stringify({ username: "test", password: "test" })},);
    let response = JSON.parse((reply.responseBody));
    let token = response['token'];

    if (!token) {
     throw new Error("Failed to retrieve token from authentication endpoint");
    }

    var subrequestHeaders = {
      "Authorization": "Bearer " + token,
      "Content-Type": "application/json"
     };
    let backend_reply = await r.subrequest('/api/users', {
      headers: subrequestHeaders
      });

r.return(backend_reply.status, JSON.stringify(backend_reply));

 }catch (e) {
    r.return(500, e);
} 

AbdallahTarabish avatar Mar 27 '23 11:03 AbdallahTarabish