@@ -131,8 +131,9 @@ public function isConnected($id = null)
131
131
*/
132
132
public function disconnect ($ redirectPath = '/ ' , $ logout = true , $ id = null )
133
133
{
134
- $ id = ($ id ) ? $ id : auth ()->id ();
135
- $ token = MsGraphToken::where ('user_id ' , $ id )->first ();
134
+ $ id = ($ id ) ? $ id : auth ()->id ();
135
+ $ token = MsGraphToken::where ('user_id ' , $ id )->latest ()->first ();
136
+
136
137
if ($ token != null ) {
137
138
$ token ->delete ();
138
139
}
@@ -155,7 +156,7 @@ public function getAccessToken($id = null, $returnNullNoAccessToken = null)
155
156
{
156
157
//use id if passed otherwise use logged in user
157
158
$ id = ($ id ) ? $ id : auth ()->id ();
158
- $ token = MsGraphToken::where ('user_id ' , $ id )->first ();
159
+ $ token = MsGraphToken::where ('user_id ' , $ id )->where ( ' refresh_token ' , ' <> ' , '' )-> latest ()-> first ();
159
160
160
161
// Check if tokens exist otherwise run the oauth request
161
162
if (!isset ($ token ->access_token )) {
@@ -202,9 +203,8 @@ public function getAccessToken($id = null, $returnNullNoAccessToken = null)
202
203
*/
203
204
public function getTokenData ($ id = null )
204
205
{
205
- $ id = $ id ?: auth ()->id ();
206
-
207
- return MsGraphToken::where ('user_id ' , $ id )->first ();
206
+ $ id = ($ id ) ? $ id : auth ()->id ();
207
+ return MsGraphToken::where ('user_id ' , $ id )->where ('refresh_token ' , '<> ' , '' )->latest ()->first ();
208
208
}
209
209
210
210
/**
0 commit comments