invisnik / laravel-steam-auth

Laravel Steam Auth
MIT License
172 stars 67 forks source link

Cant login on Laravel 5.4 #66

Closed osmancandurdu closed 7 years ago

osmancandurdu commented 7 years ago

I use Laravel 5.4 on my project. But cant login and didnt create new users on database. My Routes:

Route::get('/', function () {
    return view('welcome');
});

Route::get('login', 'AuthController@login')->name('login');

Route::post('logout', 'Auth\LoginController@logout')->name('logout');

My User.php

namespace App;

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

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'avatar', 'steamid', 'username',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

My AuthController:


namespace App\Http\Controllers;

use Invisnik\LaravelSteamAuth\SteamAuth;
use App\User;
use Auth;

class AuthController extends Controller
{
    /**
     * @var SteamAuth
     */
    private $steam;

    public function __construct(SteamAuth $steam)
    {
        $this->steam = $steam;
    }

    public function login()
    {
        if ($this->steam->validate()) {
            $info = $this->steam->getUserInfo();
            if (!is_null($info)) {
                $user = User::where('steamid', $info->steamID64)->first();
                if (is_null($user)) {
                    $user = User::create([
                        'username' => $info->personaname,
                        'avatar'   => $info->avatarfull,
                        'steamid'  => $info->steamID64
                    ]);
                }
                Auth::login($user, true);
                return redirect('/'); // redirect to site
            }
        }
        return $this->steam->redirect(); // redirect to Steam login page
    }
}
go9 commented 7 years ago

In config/steam_auth.php, change 'redirect_url' to '/auth/steam/handle' You're going to have issues when you create a new user if any attributes (email and password) are not set and are not nullable.

osmancandurdu commented 7 years ago

Thank you.