diff --git a/account/jwt.go b/account/jwt.go index 0ac7c1b..aed5140 100644 --- a/account/jwt.go +++ b/account/jwt.go @@ -8,6 +8,8 @@ import ( "strconv" "time" + "github.com/samber/lo" + "go.sia.tech/jape" "git.lumeweb.com/LumeWeb/portal/api/router" @@ -122,6 +124,29 @@ func SetAuthCookie(jc jape.Context, jwt string, apiName string) { } } +func EchoAuthCookie(jc jape.Context, apiName string) { + for name, api := range apiRegistry.GetAllAPIs() { + routeableApi, ok := api.(router.RoutableAPI) + if !ok { + continue + } + + if len(apiName) > 0 && apiName != name { + continue + } + + cookies := lo.Filter(jc.Request.Cookies(), func(item *http.Cookie, _ int) bool { + return item.Name == routeableApi.AuthTokenName() + }) + + if len(cookies) == 0 { + continue + } + + http.SetCookie(jc.ResponseWriter, cookies[0]) + } +} + func ClearAuthCookie(jc jape.Context, apiName string) { for name, api := range apiRegistry.GetAllAPIs() { routeableApi, ok := api.(router.RoutableAPI)