You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created custom AuthMiddleware for sessions. But I would like make sure that on each request I update session expiration time by 5 minutes from the time user accessed a handle. How can I made this possible?
Store
store := session.New(session.Config{
Expiration: config.Conf.App.Session.Expiration * time.Minute,
CookieHTTPOnly: true,
CookieSecure: config.Conf.App.Session.CookieSecure, // True on Production
CookieSameSite: "Strict",
// Storage: Storage,
// Database Storage will be used on Production
// For development memory storage will be used
Storage: postgres.New(postgres.Config{
Host: config.Conf.AppDb.Host,
Port: config.Conf.AppDb.Port,
Database: config.Conf.AppDb.Name,
Username: config.Conf.AppDb.User,
Password: config.Conf.AppDb.Password,
Table: "fiber_storage",
Reset: false,
GCInterval: 10 * time.Second,
SslMode: "disable",
}),
Middleware
func Auth(c *fiber.Ctx) error {
sess, err := Store.Get(c)
if err != nil {
return c.Status(fiber.StatusUnauthorized).JSON(er.Unauthorized("unathorized"))
}
allowedUrls := strings.Split(c.Path(), "/")[1]
if allowedUrls == "auth" {
return c.Next()
}
if sess.Get(AUTH_KEY) == nil {
return c.Status(fiber.StatusUnauthorized).JSON(er.Unauthorized("unathorized"))
}
// Add user to the next handle
c.Locals("_user", fmt.Sprint(sess.Get(USER_ID)))
// Update Session Expiration time
return c.Next()
}
The text was updated successfully, but these errors were encountered:
I have created custom AuthMiddleware for sessions. But I would like make sure that on each request I update session expiration time by 5 minutes from the time user accessed a handle. How can I made this possible?
Store
Middleware
The text was updated successfully, but these errors were encountered: