refactor: use jape.Context

This commit is contained in:
Derrick Hammer 2024-03-17 09:09:29 -04:00
parent 9a899317c1
commit 244aa89d71
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 8 additions and 6 deletions

View File

@ -8,6 +8,8 @@ import (
"strconv"
"time"
"go.sia.tech/jape"
"git.lumeweb.com/LumeWeb/portal/api/router"
apiRegistry "git.lumeweb.com/LumeWeb/portal/api/registry"
@ -97,7 +99,7 @@ func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey,
return claim, err
}
func SetAuthCookie(w http.ResponseWriter, token string, apiName string) {
func SetAuthCookie(jc jape.Context, token string, apiName string) {
for name, api := range apiRegistry.GetAllAPIs() {
routeableApi, ok := api.(router.RoutableAPI)
if !ok {
@ -108,7 +110,7 @@ func SetAuthCookie(w http.ResponseWriter, token string, apiName string) {
continue
}
http.SetCookie(w, &http.Cookie{
http.SetCookie(jc.ResponseWriter, &http.Cookie{
Name: name,
Value: token,
Expires: time.Now().Add(24 * time.Hour),

View File

@ -118,8 +118,8 @@ func (a AccountAPI) login(jc jape.Context) {
return
}
account.SetAuthCookie(jc.ResponseWriter, middleware.DEFAULT_AUTH_COOKIE_NAME, jwt)
account.SetAuthCookie(jc.ResponseWriter, authCookieName, jwt)
account.SetAuthCookie(jc, middleware.DEFAULT_AUTH_COOKIE_NAME, jwt)
account.SetAuthCookie(jc, authCookieName, jwt)
account.SendJWT(jc, jwt)
jc.Encode(&LoginResponse{
@ -214,8 +214,8 @@ func (a AccountAPI) otpValidate(jc jape.Context) {
return
}
account.SetAuthCookie(jc.ResponseWriter, middleware.DEFAULT_AUTH_COOKIE_NAME, jwt)
account.SetAuthCookie(jc.ResponseWriter, authCookieName, jwt)
account.SetAuthCookie(jc, middleware.DEFAULT_AUTH_COOKIE_NAME, jwt)
account.SetAuthCookie(jc, authCookieName, jwt)
account.SendJWT(jc, jwt)
jc.Encode(&LoginResponse{