feat/sync-setting: TODO to get credential

This commit is contained in:
2025-11-28 10:00:29 +07:00
parent b09c9f183c
commit 1cc8702109
3 changed files with 14 additions and 6 deletions
@@ -75,13 +75,14 @@ func GuardMW(next http.Handler) http.Handler {
credential.SecretKey = r.Header.Get("X-Sync-SecretKey")
credential.UserName = r.Header.Get("X-Sync-UserName")
if credential.Source != "" || credential.SecretKey != "" || credential.UserName != "" {
ctx := context.WithValue(r.Context(), esga.SyncKey{}, credential)
// TODO: ngecall fungsi untuk dapat dari DB menlengkapi authinfo
accessDetail, err := s.GetAuthInfoByUserName(credential.UserName)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
return
}
ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail)
next.ServeHTTP(w, r.WithContext(ctx))
// TO DO:
// 1 Get user info manually (not by using token), based on credential.UserName
// 2 To cover the point 1, Adjust /use-case/main-use-case/authentication to have the function
// 3 Any DTO that is used in the sync, add flag Sync (tru/false), set it true if it is from sync
return
}
+1
View File
@@ -22,6 +22,7 @@ type AuthInfo struct {
Pharmachist_Code *string
Intern_Position_Code *string
Roles []string
Sync bool
// User_DivisionPositions []DivisionPosition
}
@@ -179,6 +179,12 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode
return token, "", ""
}
func GetAuthInfoByUserName(userName string) (data *pa.AuthInfo, err error) {
// disini isi var `data`
// return error jika terjadi apa2
return
}
func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) {
token, errCode, errDetail := VerifyToken(r, tokenType)
if errCode != "" {