0

I do my authentication via a restful API which I validate, if its successful it gives me the username and i take that and try to login to my Laravel app. When I finish logging in, it seems to work. However, It doesn't seem to be keeping session as I navigate around the site I am still authenticated as a guest.

public function login(){
    // I do a guzzle request that gives me the value of $response['username']
    $Username = $response['username'];
    $user = User::where('username','thomc')->first();
    Auth::login($user);
    return view('home');
}

This is my User model:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    protected $table = 'UserDetails';
}

My table:

  • Username
  • Email
  • First_Name
  • Last_Name
  • BA
  • Facebook_ID
  • Google_ID

1 Answer 1

0

Not sure if it's a test change, but you're not using the $Username, instead searching for the user thomc. Another thing to note would be check if the user with username exists in the database, if not the $user returned would be null. Try login with id as well.

$username = $response['username'];
$user = User::where('username', $username)->firstOrFail();
Auth::loginUsingId($user->id);

Also make sure all the routes are wrapped with the web middleware, and appropriate auth and guest middleware on routes as needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.