From 020a326f46bf78cae570f0ea219e554ac4efcc28 Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Thu, 26 Oct 2023 23:07:00 +0200 Subject: [PATCH] feat: :sparkles: use mongodb session store --- core/app.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/app.go b/core/app.go index 3c9bf25..63b10e8 100644 --- a/core/app.go +++ b/core/app.go @@ -12,14 +12,18 @@ import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "golang.org/x/oauth2" + "gopkg.in/mgo.v2" + + mongodbstore "github.com/2-72/gorilla-sessions-mongodb" ) type App struct { MongoClient *mongo.Client + MgoClient *mgo.Session SpotifyAuth *spotifyauth.Authenticator SpotifyOAuthConfig *oauth2.Config Mux *chi.Mux - SessionStore *sessions.CookieStore + SessionStore sessions.Store } func (a App) Run() { @@ -35,8 +39,6 @@ func (a App) Shutdown() error { } func NewApp() *App { - store := sessions.NewCookieStore([]byte(viper.GetString("server.sessionkey"))) - serverAPI := options.ServerAPI(options.ServerAPIVersion1) opts := options.Client().ApplyURI(viper.GetString("mongodb.uri")).SetServerAPIOptions(serverAPI) // Create a new client and connect to the server @@ -45,6 +47,11 @@ func NewApp() *App { panic(err) } + store, err := mongodbstore.NewMongoDBStore(client.Database("listy").Collection("sessions"), []byte(viper.GetString("server.sessionkey"))) + if err != nil { + panic(err) + } + redirectURL := url.URL{ Scheme: viper.GetString("server.scheme"), Host: viper.GetString("server.host"),