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

Endpoint axios calls can't be extended #1289

Closed
stephenjason89 opened this issue Sep 3, 2021 · 3 comments
Closed

Endpoint axios calls can't be extended #1289

stephenjason89 opened this issue Sep 3, 2021 · 3 comments
Labels

Comments

@stephenjason89
Copy link

stephenjason89 commented Sep 3, 2021

Thank you for the wonderful plugin.
I am having issues with extending axios
This works a little bit

Upon getting a token (login)
I don't exactly know why my header is being stripped X-Tenant
data.tenant works

After bearer token is returned,
the next request to endpoints.user.url is converted to POST and data.tenant is attached since headers are being stripped.

After a page refresh,
axios call to user is not working since it is not being converted to post i don't know why it is not being extended.
it doesn't get called in $axios.onRequest

"@nuxtjs/auth-next": "^5.0.0-1621716493.b9b36c6",

axios.js

import { getSubdomain } from '~/assets/js/utils'

export default function ({ $axios, req }) {
    $axios.onRequest((config) => {
        if (!config.data) {
            // Making it a post request to attach data.tenant since headers are magically stripped
            config.method = 'post'
            config.data = {}
        }
        config.data.tenant = getSubdomain(process.server ? req.headers.host : location.hostname)
        config.headers.common['X-Tenant'] = getSubdomain(
            process.server ? req.headers.host : location.hostname,
        )
    })
}
strategies: {
            laravelPassportPasswordGrant: {
                provider: 'laravel/passport',
                url: '/backend',
                endpoints: {
                    user: {
                        url: '/api/user',
                    },
                },
                token: {
                    maxAge: 60 * 60 * 2,
                },
                refreshToken: {
                    maxAge: 60 * 60 * 24 * 30,
                },
                clientId: process.env.PASSPORT_CLIENT_ID,
                clientSecret: process.env.PASSPORT_CLIENT_SECRET,
                grantType: 'password',
            },
            }
@stephenjason89
Copy link
Author

image

As you can see here, X-Tenant header is sent as foo

but after dumping with my MW
image

The header X-Tenant is missing.
image

It was stripped here Request URL: http://foo.localhost:3000/_auth/laravelPassportPasswordGrant/token

@bmulholland
Copy link
Contributor

I recognize that this is some months later, but we've recently upgraded axios. Are you still facing this issue with the latest auth-next?

@stephenjason89
Copy link
Author

@bmulholland thank you for replying. I've written my own auth and didn't made use of nuxt/auth anymore as this was crucial for me. I can't verify if this is fixed at the moment.

Thank you

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

No branches or pull requests

2 participants