Jwt-auth: Single device login

Created on 21 Mar 2018  Â·  11Comments  Â·  Source: tymondesigns/jwt-auth

Subject of the issue

I want to allow 1 user can only login via 1 device.
e.g.
User 1 login from device 1
User 1 login from device 2 (system will force the device 1 to logout)

Your environment

| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | yes
| Framework | Laravel
| Framework version | 5.5
| Package version | dev-develop
| PHP version | 7.2

Most helpful comment

How to resolved follow bellow:

  1. Store token when use logined
  2. Invalidate token on next time login
 JWTAuth::setToken($user->lastest_token);
 JWTAuth::invalidate();

All 11 comments

How to resolved follow bellow:

  1. Store token when use logined
  2. Invalidate token on next time login
 JWTAuth::setToken($user->lastest_token);
 JWTAuth::invalidate();

Thank you! It works for me. @ngodinhngoc

@ngocnd0242, @TroyRay
Hi!
I have the same problem.
Could you please tell what version of JWT-auth you use? And where exactly should i add this code to make users be logged in only from one device?

@TroyRay @ngocnd0242 @jslim89 @roman-briazgalov @MitchellMcKenna
Hi,
How & where do you implement this ? I couldnt figure it out in Laravel 5.7,

I have basic login controller, tried implementing there but failed. help needed

Hello there,
I am new here and i have a question. Is is possible to get token from 2
different variables other than email and password? Please help!

On Sat, Aug 24, 2019, 6:04 AM Ayaz notifications@github.com wrote:

@TroyRay https://github.com/TroyRay @ngocnd0242
https://github.com/ngocnd0242 @jslim89 https://github.com/jslim89
@roman-briazgalov https://github.com/roman-briazgalov @MitchellMcKenna
https://github.com/MitchellMcKenna
Hi,
How & where do you implement this ? I couldnt figure it out in Laravel 5.7,

I have basic login controller, tried implementing there but failed. help
needed

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tymondesigns/jwt-auth/issues/1531?email_source=notifications&email_token=AHFZQBNKR5QVTJ2DUKPBXH3QGEBRJA5CNFSM4EWL63QKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5B5DCA#issuecomment-524538248,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHFZQBKL3AMZVT32PSIB5ADQGEBRJANCNFSM4EWL63QA
.

@TroyRay @ngocnd0242 @jslim89 @roman-briazgalov @MitchellMcKenna
Hi,
How & where do you implement this ? I couldnt figure it out in Laravel 5.7,

I have basic login controller, tried implementing there but failed. help needed

Hi!
i made it by Laravel methods:
https://laravel.com/docs/5.8/authentication#invalidating-sessions-on-other-devices

I have just added this code in LoginController:
public function authenticated(Request $request)
{
Auth::logoutOtherDevices($request->password);
}

@roman-briazgalov hey, can you share your auth controller, I dont know why i'm failing to do that..
may be my brain is exhausted by continuous work,
Really appreciate it!

@roman-briazgalov I don't get how you managed to use normal LoginController methods implementing JWT. The authenticated function is only triggered if you don't override your login function, or if you return "sendLoginresponse()"

return $this->sendLoginResponse($request);

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@ngocnd0242, @TroyRay
Hi!
I have the same problem.
Could you please tell what version of JWT-auth you use? And where exactly should i add this code to make users be logged in only from one device?

Sorry for inlate reply, I used this version "tymon/jwt-auth": "1.0.0-rc.2"

@TroyRay @ngocnd0242 @jslim89 @roman-briazgalov @MitchellMcKenna
Hi,
How & where do you implement this ? I couldnt figure it out in Laravel 5.7,
I have basic login controller, tried implementing there but failed. help needed

Hi!
i made it by Laravel methods:
https://laravel.com/docs/5.8/authentication#invalidating-sessions-on-other-devices

I have just added this code in LoginController:
public function authenticated(Request $request)
{
Auth::logoutOtherDevices($request->password);
}

@roman-briazgalov sorry for inlate reply, I used for "laravel/framework": "5.6.*",

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harveyslash picture harveyslash  Â·  3Comments

Rasoul-Karimi picture Rasoul-Karimi  Â·  3Comments

shah-newaz picture shah-newaz  Â·  3Comments

functionpointdaniel picture functionpointdaniel  Â·  3Comments

lloy0076 picture lloy0076  Â·  3Comments