Skip to content

Commit

Permalink
update session
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Aug 10, 2023
1 parent 49d9143 commit 0609e60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"fmt"
legacyauth "github.com/dapperlabs/flow-playground-api/auth/legacy"
playgroundErrors "github.com/dapperlabs/flow-playground-api/middleware/errors"
"github.com/dapperlabs/flow-playground-api/middleware/sessions"
"github.com/dapperlabs/flow-playground-api/model"
"github.com/dapperlabs/flow-playground-api/storage"
Expand Down Expand Up @@ -67,10 +68,13 @@ func (a *Authenticator) GetOrCreateUser(ctx context.Context) (*model.User, error
// Try to load existing user
if session.Values[userIDKey] != nil {
user, err = a.getCurrentUser(session.Values[userIDKey].(string))
if err == nil {
if err != nil {
fmt.Printf("Failed to load user id %s from session\n", session.Values[userIDKey].(string))
} else {
userLoaded = true
}
} else {
return nil, playgroundErrors.NewAuthorizationError("userID is missing from existing session")
}
}

Expand All @@ -86,6 +90,7 @@ func (a *Authenticator) GetOrCreateUser(ctx context.Context) (*model.User, error

err = sessions.Save(ctx, session)
if err != nil {
fmt.Println("FAILED TO UPDATE SESSION")
return nil, errors.Wrap(err, "failed to update session")
}

Expand Down
2 changes: 2 additions & 0 deletions middleware/sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func Middleware(store sessions.Store) func(http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), sessionCtxKeySession, store)

fmt.Println("Request: ", r.Header)

fmt.Println("Sessions Middleware Handler:")
session, err := store.Get(r, "flow-playground")
if err != nil {
Expand Down

0 comments on commit 0609e60

Please sign in to comment.