From 8edd16e6ab4ff7b1fbba060f9cbb3250ed13d9da Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 9 Sep 2021 15:06:11 +0200 Subject: [PATCH] update(error): front error during Spotify connection (#6) --- server.go | 12 +++++++++++- views/spotify-token.html | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 views/spotify-token.html diff --git a/server.go b/server.go index 4edd392..a98189c 100644 --- a/server.go +++ b/server.go @@ -173,15 +173,24 @@ func getNew(c *fiber.Ctx) error { } func mytoken(c *fiber.Ctx) error { + //if c.Query("error") return c.BodyParser(&SpotifyAPI) } +func spotifyCallback(c *fiber.Ctx) error { + if c.Query("error") != "" { + return c.Render("index", fiber.Map{"error": "Erreur lors de la connexion.",}) + } else { + return c.Render("spotify-token", fiber.Map{}) + } +} + func index(c *fiber.Ctx) error { return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(),}) } func main() { - //app := fiber.New(fiber.Config(Views: html, ViewsLayout: "layouts/mainbbb")) + //app := fiber.New(fiber.Config(Views: html, ViewsLayout: "layouts/main")) app := fiber.New(fiber.Config{Views: html.New("./views", ".html"),}) app.Static("/", "./static") @@ -189,6 +198,7 @@ func main() { app.Get("/hello", hello) app.Get("/refresh", getNew) app.Get("/spotify", loginSpotify) + app.Get("/callback", spotifyCallback) app.Post("/back", formHandler) app.Post("/mytoken", mytoken) diff --git a/views/spotify-token.html b/views/spotify-token.html new file mode 100644 index 0000000..163b0b9 --- /dev/null +++ b/views/spotify-token.html @@ -0,0 +1 @@ +