Make SuperUser functions more resiliant to nil values

This commit is contained in:
Denis Arh
2020-01-18 07:05:34 +01:00
parent 133fe3aab2
commit 41ce1b1c75
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -43,5 +43,5 @@ func NewSuperUserIdentity() *Identity {
}
func IsSuperUser(i Identifiable) bool {
return superUserID == i.Identity()
return i != nil && superUserID == i.Identity()
}
+4 -1
View File
@@ -40,7 +40,10 @@ func SetSuperUserContext(ctx context.Context) context.Context {
su := NewSuperUserIdentity()
ctx = SetIdentityToContext(ctx, su)
ctx = SetJwtToContext(ctx, DefaultJwtHandler.Encode(su))
if DefaultJwtHandler != nil {
ctx = SetJwtToContext(ctx, DefaultJwtHandler.Encode(su))
}
return ctx
}