You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## What kind of change does this PR introduce?
* removes the warning from being logged everytime `getSession` is called
* only log the warning if the user property is being accessed from the
session
* addresses #873, supabase/supabase-js#1010
@@ -932,15 +930,6 @@ export default class GoTrueClient {
932
930
})
933
931
})
934
932
935
-
if(result.data&&this.storage.isServer){
936
-
if(!this.insecureGetSessionWarningShown){
937
-
console.warn(
938
-
'Using supabase.auth.getSession() is potentially insecure as it loads data directly from the storage medium (typically cookies) which may not be authentic. Prefer using supabase.auth.getUser() instead. To suppress this warning call supabase.auth.getUser() before you call supabase.auth.getSession().'
939
-
)
940
-
this.insecureGetSessionWarningShown=true
941
-
}
942
-
}
943
-
944
933
returnresult
945
934
}
946
935
@@ -1120,26 +1109,18 @@ export default class GoTrueClient {
1120
1109
1121
1110
if(!hasExpired){
1122
1111
if(this.storage.isServer){
1123
-
letuser=currentSession.user
1124
-
1125
-
delete(currentSessionasany).user
1126
-
1127
-
Object.defineProperty(currentSession,'user',{
1128
-
enumerable: true,
1129
-
get: ()=>{
1130
-
if(!(currentSessionasany).__suppressUserWarning){
1131
-
// do not suppress this warning if insecureGetSessionWarningShown is true, as the data is still not authenticated
// only show warning when the user object is being accessed from the server
1132
1116
console.warn(
1133
1117
'Using the user object as returned from supabase.auth.getSession() or from some supabase.auth.onAuthStateChange() events could be insecure! This value comes directly from the storage medium (usually cookies on the server) and many not be authentic. Use supabase.auth.getUser() instead which authenticates the data by contacting the Supabase Auth server.'
'Using supabase.auth.getSession() is potentially insecure as it loads data directly from the storage medium (typically cookies) which may not be authentic'
961
-
)
962
-
).toEqual(true)
963
-
expect(
964
-
lastWarning[0].startsWith(
965
-
'Using the user object as returned from supabase.auth.getSession() '
966
-
)
967
-
).toEqual(true)
950
+
expect(warnings.length).toEqual(0)
968
951
})
969
952
970
953
test('getSession() emits one insecure warning',async()=>{
0 commit comments