feat: add SetAuthCookie helper

This commit is contained in:
Derrick Hammer 2024-03-17 08:15:27 -04:00
parent b03e6815e2
commit 51c7211c39
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"crypto/ed25519"
"errors"
"fmt"
"net/http"
"strconv"
"time"
@ -89,3 +90,14 @@ func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey,
return claim, err
}
func SetAuthCookie(w http.ResponseWriter, name, token string) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: token,
Expires: time.Now().Add(24 * time.Hour),
Secure: true,
HttpOnly: true,
Path: "/",
})
}