auto logout

This commit is contained in:
Sas Andy
2024-12-12 09:53:29 +07:00
parent ecc5dfd9c0
commit 66333ea727
13 changed files with 611 additions and 23 deletions

View File

@@ -42,16 +42,21 @@ func ParseJSON(r *http.Request, v any) error {
}
func GetTokenFromRequest(r *http.Request) string {
tokenAuth := r.Header.Get("Authorization")
if strings.HasPrefix(tokenAuth, "Bearer ") {
return strings.TrimPrefix(tokenAuth, "Bearer ")
}
// fmt.Printf("Request: %v\n", r.)
var tokenAuth string
tokenAuth = r.Header.Get("Authorization")
// fmt.Printf("Token Auth: %v\n", tokenAuth)
tokenQuery := r.URL.Query().Get("token")
// fmt.Printf("Token Query: %v\n", tokenQuery)
if tokenQuery != "" {
return tokenQuery
tokenAuth = tokenQuery
}
return ""
tokenAuth = strings.TrimSpace(tokenAuth)
tokenAuth = strings.ReplaceAll(tokenAuth, "Bearer", "")
tokenAuth = strings.ReplaceAll(tokenAuth, "\"", "")
tokenAuth = strings.TrimSpace(tokenAuth)
return tokenAuth
}
func MatchStruct(src interface{}, dst interface{}) error {