diff --git a/internal/interface/main-handler/authentication/authentication.go b/internal/interface/main-handler/authentication/authentication.go index 2b3cf437..37b84346 100644 --- a/internal/interface/main-handler/authentication/authentication.go +++ b/internal/interface/main-handler/authentication/authentication.go @@ -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)) }) } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index f023d4b8..8d0efe0f 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -9,6 +9,7 @@ import ( /******************** external ********************/ a "github.com/karincake/apem" + hk "github.com/karincake/hongkue" /******************** infra ********************/ gs "simrs-vx/internal/infra/gorm-setting" @@ -17,6 +18,7 @@ import ( /******************** pkg ********************/ cmw "simrs-vx/pkg/cors-manager-mw" hc "simrs-vx/pkg/handler-crud-helper" + lh "simrs-vx/pkg/lang-helper" handlerlogger "simrs-vx/pkg/middleware/handler-logger" ///// Internal @@ -28,6 +30,7 @@ func SetRoutes() http.Handler { ///// a.RegisterExtCall(gs.Adjust) a.RegisterExtCall(ssdb.Init) + a.RegisterExtCall(lh.Populate) r := http.NewServeMux() @@ -35,7 +38,8 @@ func SetRoutes() http.Handler { r.HandleFunc("/", home.Home) r.HandleFunc("POST /v1/authentication/login", auth.Login) - r.HandleFunc("POST /v1/authentication/logout", auth.Logout) + // r.HandleFunc("POST /v1/authentication/logout", auth.Logout) + hk.Route("POST /v1/authentication/logout", r, auth.GuardMW, auth.Logout) hc.RegCrud(r, "/v1/user", user.O) diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 0a4383e1..069958c7 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -9,7 +9,7 @@ import ( "github.com/golang-jwt/jwt" "github.com/google/uuid" - dg "github.com/karincake/apem/db-gorm-mysql" + dg "github.com/karincake/apem/db-gorm-pg" d "github.com/karincake/dodol" l "github.com/karincake/lepet" diff --git a/internal/use-case/main-use-case/authentication/helper.go b/internal/use-case/main-use-case/authentication/helper.go index 2a9a9c92..de618b5c 100644 --- a/internal/use-case/main-use-case/authentication/helper.go +++ b/internal/use-case/main-use-case/authentication/helper.go @@ -1,12 +1,12 @@ package authentication import ( - dg "github.com/karincake/apem/db-gorm-mysql" + dg "github.com/karincake/apem/db-gorm-pg" ) // just return the error code func GetAndCheck(input, condition any) (eCode string) { - result := dg.I.Where(condition).Find(input) + result := dg.I.Where(condition).Find(&input) if result.Error != nil { return "fetch-fail" } else if result.RowsAffected == 0 {