Skip to content

Commit

Permalink
add new authentication logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip-Petruneac committed Oct 2, 2024
1 parent a00db0b commit fe6615a
Show file tree
Hide file tree
Showing 4 changed files with 465 additions and 434 deletions.
12 changes: 7 additions & 5 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,25 @@ func (app *App) LoginUser(w http.ResponseWriter, r *http.Request) {

// Add the session to the session store
sessionStore.Add(token, Session{
UserID: existingUserID,
UserID: existingUserID,
ExpiresAt: sessionExpiration,
})

// Respond to the client with the session token
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
"token": token,
"existingUserID": existingUserID,
"message": "User logged in successfully",
"token": token,
"existingUserID": existingUserID,
"message": "User logged in successfully",
})
}

func (app *App) VerifySessionToken(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("works")
// Get the session token from the cookie
cookie, err := r.Cookie("session_token")
cookie, err := r.Cookie("token")
fmt.Println("Cookie name", cookie)
if err != nil {
if err == http.ErrNoCookie {
// If the cookie is not set, return an unauthorized status
Expand Down
Loading

0 comments on commit fe6615a

Please sign in to comment.