nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

can not send any request to laravel with axios nuxt if i am not logged in with nuxt auth, i use laravel sanctum, nuxt auth, nuxt axios #1245

Closed zaidpro closed 2 years ago

zaidpro commented 3 years ago

it given try to register bug

session.php

'cookie' => env( 'SESSION_COOKIE', Str::slug(env('APPNAME', 'laravel'), '').'_session' ),

cors.php

'paths' => ['api/*', 'sanctum/*'], 'allowed_methods' => ['*'], 'allowed_origins' => ['*'], 'allowed_origins_patterns' => [], 'allowed_headers' => ['*'], 'exposed_headers' => [], 'max_age' => 0, 'supports_credentials' => true,

sanctum.php

'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( '%s%s', 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000::1', env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : '' ))),

.env

SESSION_DRIVER=cookie SANCTUM_STATEFUL_DOMAINS=localhost:3000,localhost SESSION_DOMAIN=localhost

api.php

Route::post('/register',[AuthController::class, 'register']);

nuxt.config.js

modules: [ '@nuxtjs/axios', '@nuxtjs/auth-next', ],

axios: { credentials: true, baseURL: "http://localhost:8000", }, auth: { strategies: { laravelSanctum: { provider:'laravel/sanctum', url:'http://localhost:8000', endpoints: { login: { url: '/api/login', method: 'post', propertyName:'meta.token' }, logout: { url: '/api/logout', method: 'post' }, user: {url:'/api/user', method:'get', propertyName:'data'} }, }, } , redirect: { login: '/login', logout: '/login', home: '/dashboard' }, watchLoggedIn: true, autoFetchUser: true, },

register.vue

when press submit

Request URL: http://localhost:8000/sanctum/csrf-cookie Referrer Policy: strict-origin-when-cross-origin Provisional headers are shown Accept: application/json, text/plain, / Referer: http://localhost:3000/ sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91" sec-ch-ua-mobile: ?0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36 X-XSRF-TOKEN: eyJpdiI6InU5dVg1bmttOVdycHBiN3NHcUYwVGc9PSIsInZhbHVlIjoiM0wwQlAzVHRSU25tVkYrYWcrb2lwTG1peTFXVndtWTJLU1YvMW1zZFYwT0VmbmtVUXYzd2VweTVUWlBLZUs0WXUvMVNYRXVaOHZGbjdZM3hnS1Z1RXNRcVdsZ1NmVGwzL2p3NlJBV3lVbnN1YWtoem9pSVIzWlpzUWpNNm5mUk8iLCJtYWMiOiJiMjcyYWFhNTUyYzhhMmI3ZmRhODc4ODEyYzExYjE3MzgxYmQ0OTIwOTYxNzNkNTlhOTNkNTJhYWRmYzY1MTI0In0=

Majid-Kamali commented 3 years ago

that is my problem to anyone have solution for this problem

zaidpro commented 3 years ago

and in my url after hit enter it will be -> http://localhost:3000/register?userName=Zaid%20Proo&email=test%40test&password=password, and request will be canceled, like image above, any body can tell me where this url is come? it is post request and i have no userName in data it is name

chapus commented 3 years ago

image

Im getting the same error, client cancelling XHR request, server not receiving the request.