#session error

10 messages · Page 1 of 1 (latest)

slender geode
#

im trying to make auth restful api, but why am i always getting this session error when im not even using it?

#

Illuminate\Database\QueryException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "sessions" does not exist

#

is this due to laravel 11?

stable spire
#

You're using the database session driver

heavy osprey
#

I want to know the issue in deeply because there can be several reasons.

slender geode
#

i did this on my User model so i can do Auth::login($user)

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class User extends Model implements Authenticatable
{

and on middleware i did this :

public function handle(Request $request, Closure $next): Response
    {

        $token = $request->header("Authorization");
        $authenticate = true;

        if (!$token) {
            $authenticate = false;
        };

        $user = User::where("token", $token)->first();

        if (!$user) {
            $authenticate = false;
        } else {
            Auth::login($user);
        }

        if ($authenticate) {
            return $next($request);
        } else {
            return response()->json([
                "errors" => [
                    "message" => "Unauthorized"
                ]
            ])->setStatusCode(401);
        }
    }

and then when i try to do unit test, it gives the 500 error (the session one)

public function testGetUserSuccess()
    {
        $this->seed(UserSeeder::class);

        $this->get("/api/auth/users/current", [
            "Authorization" => "test"
        ])->assertStatus(200)
        ->assertJson([
            "data"=> [
                "username" => "test",
                "name"=> "test"
            ]
        ]);
    }
slender geode
wise tendon