Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Update Session expiration ? #1962

Closed
rngallen opened this issue Jul 2, 2022 · 1 comment · Fixed by #1960
Closed

How to Update Session expiration ? #1962

rngallen opened this issue Jul 2, 2022 · 1 comment · Fixed by #1960

Comments

@rngallen
Copy link

rngallen commented Jul 2, 2022

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()
}
@ReneWerner87 ReneWerner87 linked a pull request Jul 4, 2022 that will close this issue
@ReneWerner87
Copy link
Member

ReneWerner87 commented Jul 4, 2022

fix is marked for the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants