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

Working locally, but not on the prod server (maybe some domains issue) #2275

Closed
Vetlin opened this issue Jun 29, 2021 · 1 comment
Closed
Labels
question Ask how to do something or how something works

Comments

@Vetlin
Copy link

Vetlin commented Jun 29, 2021

I am using auth next with laravel sanctum provider to communicate with laravel api. On my local I have nuxt app on port 3000 and laravel app on port 8000, so the urls are http://localhost:8000 and http://localhost:3000 💬
Also I have prod server set like this
Nuxt - http://maindomain.com
Laravel Api - http://api.maindomain.com

Here is my nuxt.config.js file

export default {
    // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
    ssr: false,

    // Global page headers: https://go.nuxtjs.dev/config-head
    head: {
        titleTemplate: '%s - Linevich Auto',
        title: 'LinAuto',
        htmlAttrs: {
            lang: 'en'
        },
        meta: [
            {charset: 'utf-8'},
            {name: 'viewport', content: 'width=device-width, initial-scale=1'},
            {hid: 'description', name: 'description', content: ''}
        ],
        link: [
            {rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'},
            {rel: 'preconnect', href: 'https://fonts.gstatic.com'},
            {rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap'},
        ]
    },

    // Global CSS: https://go.nuxtjs.dev/config-css
    css: [],

    // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
    plugins: [],

    // Auto import components: https://go.nuxtjs.dev/config-components
    components: true,

    // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
    buildModules: [
        // https://go.nuxtjs.dev/vuetify
        '@nuxtjs/vuetify',
        '@nuxtjs/dotenv',
    ],

    // Modules: https://go.nuxtjs.dev/config-modules
    modules: [
        '@nuxtjs/axios',
        '@nuxtjs/auth-next',
    ],

    // Axios module configuration: https://go.nuxtjs.dev/config-axios
    axios: {
        proxy: true,
        credentials: true,
    },

    // Build Configuration: https://go.nuxtjs.dev/config-build
    build: {},

    auth: {
        redirect: {
            login: '/user/login',
            logout: '/',
            callback: '/login',
            home: '/'
        },
        strategies: {
            laravelSanctum: {
                provider: 'laravel/sanctum',
                url: process.env.API_URL,
                endpoints: {
                    login: {url: '/api/user/login', method: 'post'},
                    user: {url: '/api/user', method: 'get'}
                }
            },
        },
    },
    proxy: {
        '/laravel': {
            target: 'https://laravel-auth.nuxtjs.app',
            pathRewrite: { '^/laravel': '/' }
        }
    },
}

Here is my login logic on login page

export default {
    name: "login",
    data: () => ({
        email: '',
        password: '',
    }),
    methods: {
        async login() {
            await this.$auth.loginWith('laravelSanctum', {
                data: {
                    email: this.email,
                    password: this.password,
                },
            })
            this.$router.push('/admin')
        },
    },
}

Admin page is under auth middleware.

So the problem is that on my local auth happens successfully, but when I try to login on prod server - nothing happens. In network I see that backend returned successful response, but I'm still on login page. I debug it a little bit, I log to console the state of this.$auth.user after login but before redirect, and on local it is returning user object as expected, but on prod - false.

So what can be the issue here? Is it related to the laravel api subdomain?

@Vetlin Vetlin added the question Ask how to do something or how something works label Jun 29, 2021
@mahieyin-rahmun
Copy link
Contributor

Hi. I believe you have the libraries mixed up. I assume this is where the issue should be filed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants