Skip to content

Commit

Permalink
chore: adding level
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jul 3, 2024
1 parent a62efab commit 7508a73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions goth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp"
"github.com/zeiss/fiber-goth/adapters"
Expand Down Expand Up @@ -223,25 +224,31 @@ func (CompleteAuthCompleteHandler) New(cfg Config) fiber.Handler {

provider, err := providers.GetProvider(p)
if err != nil {
return cfg.ErrorHandler(c, err)
return cfg.ErrorHandler(c, ErrMissingProviderName)
}

log.Infow("", "provider", provider.Name())

user, err := provider.CompleteAuth(c.Context(), cfg.Adapter, &Params{ctx: c})
if err != nil {
return cfg.ErrorHandler(c, err)
return cfg.ErrorHandler(c, ErrMissingUser)
}

log.Infow("", "user", user.Email)

duration, err := time.ParseDuration(cfg.Expiry)
if err != nil {
return cfg.ErrorHandler(c, err)
return cfg.ErrorHandler(c, ErrMissingSession)
}
expires := time.Now().Add(duration)

session, err := cfg.Adapter.CreateSession(c.Context(), user.ID, expires)
if err != nil {
return cfg.ErrorHandler(c, err)
return cfg.ErrorHandler(c, ErrMissingSession)
}

log.Infow("", "session", session.SessionToken)

cookieValue := fasthttp.Cookie{}
cookieValue.SetKeyBytes([]byte(cfg.CookieName))
cookieValue.SetValueBytes([]byte(session.SessionToken))
Expand Down Expand Up @@ -543,8 +550,8 @@ var ConfigDefault = Config{
}

// default ErrorHandler that process return error from fiber.Handler
func defaultErrorHandler(_ *fiber.Ctx, _ error) error {
return fiber.ErrBadRequest
func defaultErrorHandler(_ *fiber.Ctx, err error) error {
return NewError(http.StatusBadRequest, err.Error())
}

// default filter for response that process default return.
Expand Down
2 changes: 1 addition & 1 deletion scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
# This script is executed after the creation of a new project.

go install github.com/cosmtrek/air@latest
go install github.com/air-verse/air@latest

0 comments on commit 7508a73

Please sign in to comment.