feat (auth): rework logout
This commit is contained in:
@@ -15,7 +15,7 @@ type authKey string
|
||||
|
||||
const akInfo authKey = "authInfo"
|
||||
|
||||
type Key struct{}
|
||||
type AuthKey struct{}
|
||||
|
||||
// var Position m.Position
|
||||
|
||||
@@ -35,12 +35,12 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func Logout(w http.ResponseWriter, r *http.Request) {
|
||||
authInfoContext := context.Context.Value(r.Context(), akInfo)
|
||||
if authInfoContext == nil {
|
||||
ctxVal := r.Context().Value(AuthKey{})
|
||||
if ctxVal == nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "logout skiped. the request is done wihtout authorization."}, nil)
|
||||
return
|
||||
}
|
||||
authInfo := context.Context.Value(r.Context(), akInfo).(*s.AuthInfo)
|
||||
authInfo := ctxVal.(*s.AuthInfo)
|
||||
s.RevokeToken(authInfo.Uuid)
|
||||
rw.WriteJSON(w, http.StatusOK, d.IS{"message": "logged out"}, nil)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func GuardMW(next http.Handler) http.Handler {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
|
||||
return
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), Key{}, accessDetail)
|
||||
ctx := context.WithValue(r.Context(), AuthKey{}, accessDetail)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user