Move dashboard to api

This commit is contained in:
Jan Bader 2022-01-21 14:20:12 +00:00
parent 929db00a47
commit ddab5998bc
3 changed files with 14 additions and 2 deletions

View File

@ -49,7 +49,6 @@ func (h *Handler) Serve() {
withLogin := router.Group("") withLogin := router.Group("")
withLogin.Use(h.verifyLoginWithRedirect) withLogin.Use(h.verifyLoginWithRedirect)
withLogin.GET("/dashboard", h.dashboard)
withLogin.GET("/admin", h.admin) withLogin.GET("/admin", h.admin)
withLogin.GET("/admin/clear-database", h.clearDatabase) withLogin.GET("/admin/clear-database", h.clearDatabase)
@ -75,6 +74,7 @@ func (h *Handler) Serve() {
authenticated := api.Group("") authenticated := api.Group("")
authenticated.Use(h.verifyLoginWithRedirect) authenticated.Use(h.verifyLoginWithRedirect)
authenticated.GET("/dashboard", h.dashboard)
user := authenticated.Group("/user") user := authenticated.Group("/user")
user.GET("/logout", logout) user.GET("/logout", logout)

View File

@ -26,6 +26,18 @@ func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, error) {
return token, nil return token, nil
} }
func (h *Handler) verifyLoginWithForbidden(c *gin.Context) {
token, err := h.verifyLogin(c)
if err != nil {
//c.Header("WWW-Authenticate", "Bearer")
c.AbortWithStatus(http.StatusForbidden)
return
}
c.Set("token", token)
c.Next()
}
func (h *Handler) verifyLoginWithRedirect(c *gin.Context) { func (h *Handler) verifyLoginWithRedirect(c *gin.Context) {
token, err := h.verifyLogin(c) token, err := h.verifyLogin(c)
if err != nil { if err != nil {

View File

@ -12,7 +12,7 @@ const store = createStore({
}, },
mutations: { mutations: {
getDashboard (state) { getDashboard (state) {
fetch("/dashboard") fetch("/api/v1/dashboard")
.then(x => x.json()) .then(x => x.json())
.then(x => console.log(x)) .then(x => console.log(x))
.then(x => state.Budgets = x.Budgets); .then(x => state.Budgets = x.Budgets);