Category : laravel-sanctum

I’m using Laravel sanctum to authenticate my API, but i’m not using the default laravel User model, I’ve built a model to separate my App customers in another table called Customer. To this to work I did the alterations bellow Custom model Customer.php https://ghostbin.com/Opey3 Config file auth.php https://ghostbin.com/BsYSb Config file sanctum.php https://ghostbin.com/yDlts Route file api.php ..

Read more

I logout of my application via: Auth::guard(‘web’)->logout(); Please note, it’s the SPA use of Sanctum so no tokens. Then in my test, I check if the user is logged out via: Sanctum::actingAs(User::first(), [‘*’]); $response = $this->postJson( route(‘logout’) ); // runs auth logout $this->assertGuest(); The above fails, yet, when I do not use Sanctum::actingAs(User::first(), [‘*’]); and ..

Read more

I’m testing Laravel Sanctum with a Nuxt (v2) SSR project locally. I’m using cookie based auth and axios. When calling auth guarded routes from my app, requests are accepted (provided I’m logged in, of course). However, my API rejects requests (401, unauthorized) when calling the same routes from within the nuxtServerInit hook. This is because ..

Read more

Laravel usually use following for request validation. $request->validate([ ‘name’ => [‘required’, ‘string’, ‘max:255′], ’email’ => [‘required’, ‘string’, ’email’, ‘max:255’, ‘unique:users’, ‘required_without_all:phone’], ‘password’ => [‘required’, ‘confirmed’, RulesPassword::defaults()], ‘phone’ => [‘required’, ‘string’, ‘max:13’, ‘unique:users’, ‘required_without_all:email’], ]); This method only add $error variable that can be access using blade files as it render on server only. But now ..

Read more

Laravel usually use following for request validation. $request->validate([ ‘name’ => [‘required’, ‘string’, ‘max:255′], ’email’ => [‘required’, ‘string’, ’email’, ‘max:255’, ‘unique:users’, ‘required_without_all:phone’], ‘password’ => [‘required’, ‘confirmed’, RulesPassword::defaults()], ‘phone’ => [‘required’, ‘string’, ‘max:13’, ‘unique:users’, ‘required_without_all:email’], ]); This method only add $error variable that can be access using blade files as it render on server only. But now ..

Read more

I’ve a macbook pro with M1 chipset, I’m testing a Laravel web-app with Sanctum Api authentication. First I send a GET requesto to ‘/sanctum/csrf-cookie’ to get the cookies, then I send a POST request to the ‘/login’ endpoint I get the following error: "IlluminateDatabaseQueryException: could not find driver (SQL: select * from "users" where "email"" ..

Read more

I am using laravel-sanctum and nuxt-auth. When the user login, I set a token cookie for 2 months. const response = await this.$auth.loginWith("laravelSanctum", { data: this.form }); data = response.data; this.$auth.$storage.setCookie("login_token", data.token, { expires: 60 }); In My nuxt-auth module strategies: { ‘laravelSanctum’: { provider: ‘laravel/sanctum’, url: process.env.API_URL, cookie: { cookie: { name: ‘login_token’, // ..

Read more

the more I read about Laravel Spa (Vue) authentication, the more I ask myself about the "best way" to authenticate with Sanctum. Official Laravel documentation says: For this feature, Sanctum does not use tokens of any kind. Instead, Sanctum uses Laravel’s built-in cookie based session authentication services. This approach to authentication provides the benefits of ..

Read more

I currently have a React Application spawned via CRA running on http://paulsamazinglocalhost.com:3000 package json as follows: "start": "HOST=paulsamazinglocalhost.com PORT=3000 react-scripts start", I’m currently (trying) to talk to a Laravel API running on port 8000 specifically http://api.paulsamazinglocalhost.com:8000 spawned via laravel as follows: php artisan serve –port 8000 –host api.paulsamazinglocalhost.com Now, "what does the Laravel CORS configuration ..

Read more

I am using laravel/sanctum package for authenticating my api. I have followed all the steps from the documentation but I get 404 not found when using an invalid token for hitting a guarded route instead of 401. Route::group([‘middleware’ => [‘auth:sanctum’]], function () { Route::post("/upload", [AuthController::class, "uploadFile"]); Route::post(‘/me’, [AuthController::class, ‘me’]); }); Sourc..

Read more