Add isLoggedIn

This commit is contained in:
ferreo 2024-07-30 20:36:04 +01:00
parent c2d3850a33
commit 2dee0c9333
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,15 @@
package handlers_auth
import (
"brunel/auth"
"github.com/gofiber/fiber/v2"
)
func IsLoggedIn(c *fiber.Ctx) error {
ok, _ := auth.CheckSessionToken(c.Cookies("pt"))
if !ok {
return c.Status(fiber.StatusUnauthorized).SendString("Unauthorized")
}
return c.Status(fiber.StatusOK).SendString("Logged in")
}

View File

@ -95,9 +95,10 @@ func runServer(ctx context.Context) error {
server.Get("/api/package/:package", handlers_packages.Package) server.Get("/api/package/:package", handlers_packages.Package)
server.Get("/api/queue", handlers_build.Queue) server.Get("/api/queue", handlers_build.Queue)
server.Get("/api/errored", handlers_build.Errored) server.Get("/api/errored", handlers_build.Errored)
server.Get("/api/isloggedin", handlers_auth.IsLoggedIn)
server.Post("/api/login", handlers_auth.Login) server.Post("/api/login", handlers_auth.Login)
adminRoutes.Post("/triggerBuild", handlers_build.TriggerBuild) adminRoutes.Post("/triggerbuild", handlers_build.TriggerBuild)
adminRoutes.Post("/register", handlers_auth.Register) adminRoutes.Post("/register", handlers_auth.Register)
adminRoutes.Post("/updatePassword", handlers_auth.UpdatePassword) adminRoutes.Post("/updatePassword", handlers_auth.UpdatePassword)