From 0237c2796fd43b88b0c1a8d8936e2e73b302479f Mon Sep 17 00:00:00 2001 From: Asara Date: Sat, 28 Sep 2019 08:35:49 -0400 Subject: [PATCH] Start cookie auth --- TODO.md | 1 + main.go | 12 ++++++------ packages/auth/auth.go | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 6d8f503..1252cbf 100644 --- a/TODO.md +++ b/TODO.md @@ -1 +1,2 @@ +#. Set up cookies #. Implement comments diff --git a/main.go b/main.go index 3a597a8..71c5f49 100644 --- a/main.go +++ b/main.go @@ -52,14 +52,14 @@ func main() { func Routes() *chi.Mux { router := chi.NewRouter() - // enable cors testing - // LOCK THIS DOWN FOR PRODUCTION - cors := cors.New(cors.Options{ - AllowedOrigins: []string{"*"}, - }) + // enable cors testing + // LOCK THIS DOWN FOR PRODUCTION + cors := cors.New(cors.Options{ + AllowedOrigins: []string{"*"}, + }) router.Use( - cors.Handler, + cors.Handler, render.SetContentType(render.ContentTypeJSON), middleware.Logger, middleware.DefaultCompress, diff --git a/packages/auth/auth.go b/packages/auth/auth.go index 5e29eb3..9c11c17 100644 --- a/packages/auth/auth.go +++ b/packages/auth/auth.go @@ -42,6 +42,7 @@ type Claims struct { type JWT struct { JWT string `json:"jwt"` + Username string `json:"username"` } func Init() { @@ -151,6 +152,7 @@ func signin(w http.ResponseWriter, r *http.Request) { _, tokenString, _ := TokenAuth.Encode(claims) token := JWT{ JWT: tokenString, + Username: creds.Username, } render.JSON(w, r, token) }