Start cookie auth

This commit is contained in:
Amarpreet Minhas 2019-09-28 08:35:49 -04:00
parent deec023b7f
commit 0237c2796f
3 changed files with 9 additions and 6 deletions

View file

@ -1 +1,2 @@
#. Set up cookies
#. Implement comments #. Implement comments

12
main.go
View file

@ -52,14 +52,14 @@ func main() {
func Routes() *chi.Mux { func Routes() *chi.Mux {
router := chi.NewRouter() router := chi.NewRouter()
// enable cors testing // enable cors testing
// LOCK THIS DOWN FOR PRODUCTION // LOCK THIS DOWN FOR PRODUCTION
cors := cors.New(cors.Options{ cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, AllowedOrigins: []string{"*"},
}) })
router.Use( router.Use(
cors.Handler, cors.Handler,
render.SetContentType(render.ContentTypeJSON), render.SetContentType(render.ContentTypeJSON),
middleware.Logger, middleware.Logger,
middleware.DefaultCompress, middleware.DefaultCompress,

View file

@ -42,6 +42,7 @@ type Claims struct {
type JWT struct { type JWT struct {
JWT string `json:"jwt"` JWT string `json:"jwt"`
Username string `json:"username"`
} }
func Init() { func Init() {
@ -151,6 +152,7 @@ func signin(w http.ResponseWriter, r *http.Request) {
_, tokenString, _ := TokenAuth.Encode(claims) _, tokenString, _ := TokenAuth.Encode(claims)
token := JWT{ token := JWT{
JWT: tokenString, JWT: tokenString,
Username: creds.Username,
} }
render.JSON(w, r, token) render.JSON(w, r, token)
} }