From 4b0a0545969c8be2d1c329673b6a036af7cc8b03 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 8 Apr 2020 16:15:41 +0200 Subject: [PATCH] Update authentication on login I am not sure about this. but when we get a new access token or refresh token (which I think we do not) we update those. probably does not hurt? --- app/models/user.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index a9e3a7d..83bb70e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,12 @@ class User < ApplicationRecord user_info = oauth.get_userinfo if user = User.find_by(google_id: user_info.id) - return user, user.authentications.last + authentication = user.authentications.last + authentication.access_token = auth_client.access_token if auth_client.access_token.present? + authentication.refresh_token = auth_client.refresh_token if auth_client.refresh_token.present? + authentication.expires_at = Time.at(auth_client.expires_at) if auth_client.expires_at.present? + authentication.save + return user, authentication else user = User.create(name: user_info.name, email: user_info.email, google_id: user_info.id) authentication = user.authentications.create(