Persistent sessions are working now
This commit is contained in:
parent
5a6fcac34c
commit
36137f208f
@ -51,7 +51,9 @@ func EnableGoogleLogin(app *aero.Application) {
|
|||||||
|
|
||||||
// Auth Callback
|
// Auth Callback
|
||||||
app.Get("/auth/google/callback", func(ctx *aero.Context) string {
|
app.Get("/auth/google/callback", func(ctx *aero.Context) string {
|
||||||
if ctx.Session().ID() != ctx.Query("state") {
|
session := ctx.Session()
|
||||||
|
|
||||||
|
if session.ID() != ctx.Query("state") {
|
||||||
return ctx.Error(http.StatusUnauthorized, "Authorization not allowed for this session", errors.New("Google login failed: Incorrect state"))
|
return ctx.Error(http.StatusUnauthorized, "Authorization not allowed for this session", errors.New("Google login failed: Incorrect state"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +90,7 @@ func EnableGoogleLogin(app *aero.Application) {
|
|||||||
return ctx.Error(http.StatusForbidden, "Email not registered", err)
|
return ctx.Error(http.StatusForbidden, "Email not registered", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Session().Set("userId", user.ID)
|
session.Set("userId", user.ID)
|
||||||
|
|
||||||
return ctx.Redirect("/")
|
return ctx.Redirect("/")
|
||||||
})
|
})
|
||||||
|
15
main.go
15
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
"github.com/animenotifier/notify.moe/pages/airing"
|
"github.com/animenotifier/notify.moe/pages/airing"
|
||||||
"github.com/animenotifier/notify.moe/pages/anime"
|
"github.com/animenotifier/notify.moe/pages/anime"
|
||||||
@ -35,6 +36,20 @@ func main() {
|
|||||||
// HTTPS
|
// HTTPS
|
||||||
app.Security.Load("security/fullchain.pem", "security/privkey.pem")
|
app.Security.Load("security/fullchain.pem", "security/privkey.pem")
|
||||||
|
|
||||||
|
// Session store
|
||||||
|
app.Sessions.Store = arn.NewAerospikeStore("Session")
|
||||||
|
|
||||||
|
// Session middleware
|
||||||
|
app.Use(func(ctx *aero.Context, next func()) {
|
||||||
|
// Handle the request first
|
||||||
|
next()
|
||||||
|
|
||||||
|
// Update session if it has been modified
|
||||||
|
if ctx.HasSession() && ctx.Session().Modified() {
|
||||||
|
app.Sessions.Store.Set(ctx.Session().ID(), ctx.Session())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
app.Layout = func(ctx *aero.Context, content string) string {
|
app.Layout = func(ctx *aero.Context, content string) string {
|
||||||
return components.Layout(content)
|
return components.Layout(content)
|
||||||
|
Loading…
Reference in New Issue
Block a user