Pochwar / laravel-vue-spa

82 stars 31 forks source link

{"error":"Unauthorized"} issue in laravel 5.8 and latest vuejs #6

Open princeteck opened 5 years ago

princeteck commented 5 years ago

I tried your tutorial and was able to create it as was mentioned on medium tutorial.

But i started facing issue when i tried login.

login is successful but when user is redirected. in view it's still on login page and in network tab i get {"error":"Unauthorized"} on http://localhost:8000/api/auth/user.

image

image

i thought of downloading your git version and trying it to run and it run's successfully. but when i make changes to package.json and composer as per my requirement i get error as above. Note: i had to update the vue version to the latest in git local copy.

============== package,json ==================

{ "private": true, "scripts": { "dev": "npm run development", "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch": "npm run development -- --watch", "watch-poll": "npm run watch -- --watch-poll", "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", "prod": "npm run production", "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" }, "devDependencies": { "axios": "^0.19", "browser-sync": "^2.26.7", "browser-sync-webpack-plugin": "^2.2.2", "cross-env": "^5.1", "laravel-mix": "^4.0.7", "resolve-url-loader": "^2.3.2", "sass": "^1.15.2", "sass-loader": "^7.1.0", "vue": "^2.6.10", "vue-template-compiler": "^2.6.10", "webpack-cli": "^3.3.4" }, "dependencies": { "@chenfengyuan/vue-carousel": "^1.0.2", "@tailwindcss/custom-forms": "^0.1.*", "@websanova/vue-auth": "^2.21.14-beta", "es6-promise": "^4.2.8", "hamburgers": "^1.1.3", "moment": "^2.24.0", "tailwindcss": "^1.0.4", "vue-ads-pagination": "^2.1.4", "vue-axios": "^2.1.4", "vue-router": "^3.0.6", "vue-scrollto": "^2.15.0", "vue-tinymce-editor": "^1.6.2" } }

=============== composer.json =================

{ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", "keywords": [ "framework", "laravel" ], "license": "MIT", "require": { "php": "^7.1.3", "barryvdh/laravel-cors": "^0.11.3", "fideloper/proxy": "^4.0", "laravel/framework": "5.8.*", "laravel/tinker": "^1.0", "tymon/jwt-auth": "dev-develop" }, "require-dev": { "beyondcode/laravel-dump-server": "^1.0", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", "mockery/mockery": "^1.0", "nunomaduro/collision": "^3.0", "phpunit/phpunit": "^7.5" }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true }, "extra": { "laravel": { "dont-discover": [] } }, "autoload": { "psr-4": { "App\": "app/" }, "classmap": [ "database/seeds", "database/factories" ] }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } }, "minimum-stability": "dev", "prefer-stable": true, "scripts": { "post-autoload-dump": [ "Illuminate\Foundation\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ] } }

Pochwar commented 5 years ago

Hi, sorry for the late answer. If I understand well, the issue appears just after login when websanova's Vue Auth try to get the user's infos.

As you get the 'unauthorized' response, it's the Laravel auth middlewares that block the request. So it could be the token that is not well send - you can check it in the header's request.

It's hard to debug without being able to test and it's been a while I did'nt work on this project.

Keep me in touch if you manage to fix your issue, and if you project is versionned somewhere, give me the link so I could be able to test it and maybe find a solution :)

git-yourdevexpert commented 4 years ago

I am facing the same issue immediately after the login it gives me unauthorized response.