update auth api with session

This commit is contained in:
steven
2021-12-10 13:41:17 +08:00
parent a08ad0ebab
commit 050c2ccbd5
15 changed files with 143 additions and 90 deletions

View File

@ -10,12 +10,14 @@ type Response struct {
Data interface{} `json:"data"`
}
func GetUserIdInCookie(r *http.Request) (string, error) {
userIdCookie, err := r.Cookie("user_id")
func GetUserIdInSession(r *http.Request) (string, error) {
session, _ := SessionStore.Get(r, "session")
if err != nil {
return "", err
userId, ok := session.Values["user_id"].(string)
if !ok {
return "", http.ErrNoCookie
}
return userIdCookie.Value, err
return userId, nil
}