Passport/pkg/server/ui/index.go

42 lines
1021 B
Go
Raw Normal View History

2024-04-20 06:05:50 +00:00
package ui
import (
"fmt"
"git.solsynth.dev/hydrogen/passport/pkg/services"
"github.com/gofiber/fiber/v2"
)
func MapUserInterface(A *fiber.App, authFunc func(c *fiber.Ctx, overrides ...string) error) {
authCheckWare := func(c *fiber.Ctx) error {
var token string
if cookie := c.Cookies(services.CookieAccessKey); len(cookie) > 0 {
token = cookie
}
fmt.Println(token)
c.Locals("token", token)
if err := authFunc(c); err != nil {
fmt.Println(err)
uri := c.Request().URI().FullURI()
return c.Redirect(fmt.Sprintf("/sign-in?redirect_uri=%s", string(uri)))
} else {
return c.Next()
}
}
2024-04-20 06:05:50 +00:00
pages := A.Group("/").Name("Pages")
2024-04-20 14:50:09 +00:00
pages.Get("/sign-up", signupPage)
2024-04-20 06:05:50 +00:00
pages.Get("/sign-in", signinPage)
pages.Get("/mfa", mfaRequestPage)
pages.Get("/mfa/apply", mfaApplyPage)
2024-04-20 14:50:09 +00:00
pages.Post("/sign-up", signupAction)
pages.Post("/sign-in", signinAction)
pages.Post("/mfa", mfaRequestAction)
pages.Post("/mfa/apply", mfaApplyAction)
pages.Get("/users/me", authCheckWare, selfUserinfoPage)
2024-04-20 06:05:50 +00:00
}