Add an /api/authcheck and use it to toggle logout/login link on top header.
This commit is contained in:
parent
c2123ff741
commit
fcb71add03
3 changed files with 15 additions and 2 deletions
|
|
@ -15,6 +15,12 @@ import (
|
|||
. "MY/webapp/common"
|
||||
)
|
||||
|
||||
func GetApiAuthCheck(c *fiber.Ctx) error {
|
||||
_, err := CheckAuthed(c, false)
|
||||
// auth failure or not authed is determined by err, with nil meaning YES AUTHED
|
||||
return c.JSON(fiber.Map{"is_authed": err == nil})
|
||||
}
|
||||
|
||||
func GetApiLogout(c *fiber.Ctx) error {
|
||||
err := LogoutUser(c)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ func Setup(app *fiber.App) {
|
|||
app.Post("/api/link", PostApiLink)
|
||||
|
||||
// api/auth.go
|
||||
app.Get("/api/authcheck", GetApiAuthCheck)
|
||||
app.Get("/api/logout", GetApiLogout)
|
||||
app.Post("/api/register", PostApiRegister)
|
||||
app.Post("/api/login", PostApiLogin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue