Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer Token returns undefined #317

Open
2 tasks done
4e576rt8uh9ij9okp opened this issue Sep 7, 2024 · 1 comment
Open
2 tasks done

Bearer Token returns undefined #317

4e576rt8uh9ij9okp opened this issue Sep 7, 2024 · 1 comment

Comments

@4e576rt8uh9ij9okp
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.28.1

Plugin version

9.0.1

Node.js version

22.7

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Arch Linux

Description

I am sending a bearer auth token using fetch and on the server side (nodejs).
NodeJS logs the token twice not once. The first log shows auth token being undefined, the second log shows the token.

// Nodejs
app.addHook('onRequest', (req, rep, done) => {
    const auth = req.headers.authorization
    console.log(req.url, "auth", auth)
    done()
})

// Browser
const getData = await fetch(apiUrl, {
    method: "GET",
    headers: {
        'Authorization': `bearer ${key}`,
        'Content-Type': 'application/json',
        'origin': "*"
    }
})

What it returns

/music auth undefined
/music auth bearer secrettoken

Expected

/music auth bearer secrettoken

I'm not sure where the first request is coming from, I have also noticed that when I'm sending the request multiple times the auth token always shows, but then every ~4s it shows the auth undefined.

Link to code that reproduces the bug

No response

Expected Behavior

Not having a undefined auth token, as I am sending it over fetch() it should always be "defined" on nodejs.

@mcollina
Copy link
Member

mcollina commented Sep 9, 2024

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants