From 7ef68d030b8a62cf99f897ff8d95ccb62032fc00 Mon Sep 17 00:00:00 2001 From: vinchent Date: Mon, 19 Aug 2024 21:39:36 +0200 Subject: [PATCH] Checking authentication on the backend --- Makefile | 2 +- cmd/api/handlers-api.go | 4 ++++ cmd/api/routes-api.go | 1 + cmd/web/templates/terminal.page.gohtml | 4 +++- static/js/common.js | 29 ++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3998900..ce92185 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ STRIPE_SECRET=$(shell sed '2q;d' cred.txt) -STRIPE_KEY=$(shell sed '2q;d' cred.txt) +STRIPE_KEY=$(shell sed '1q;d' cred.txt) GOSTRIPE_PORT=4000 API_PORT=4001 DSN=vinchent:secret@tcp(localhost:3306)/widgets?parseTime=true&tls=false diff --git a/cmd/api/handlers-api.go b/cmd/api/handlers-api.go index 2767fd6..9575f4f 100644 --- a/cmd/api/handlers-api.go +++ b/cmd/api/handlers-api.go @@ -297,3 +297,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request) _ = app.writeJSON(w, http.StatusOK, payload) } + +func (app *application) CheckAuthentication(w http.ResponseWriter, r *http.Request) { + app.invalidCredentials(w) +} diff --git a/cmd/api/routes-api.go b/cmd/api/routes-api.go index ff14740..9e3e079 100644 --- a/cmd/api/routes-api.go +++ b/cmd/api/routes-api.go @@ -23,6 +23,7 @@ func (app *application) routes() http.Handler { mux.Post("/api/create-customer-and-subscribe-to-plan", app.CreateCustomerAndSubscribeToPlan) mux.Post("/api/authenticate", app.CreateAuthToken) + mux.Post("/api/is-authenticated", app.CheckAuthentication) return mux } diff --git a/cmd/web/templates/terminal.page.gohtml b/cmd/web/templates/terminal.page.gohtml index 0ad8087..73f1212 100644 --- a/cmd/web/templates/terminal.page.gohtml +++ b/cmd/web/templates/terminal.page.gohtml @@ -76,8 +76,10 @@ Virtual Terminal {{ define "js" }}