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

Empty memorysession when route contains path params #208

Open
teroz opened this issue Dec 26, 2022 · 0 comments
Open

Empty memorysession when route contains path params #208

teroz opened this issue Dec 26, 2022 · 0 comments

Comments

@teroz
Copy link

teroz commented Dec 26, 2022

Hey there I found an issue with the memorysession. When a route has a path parameter sessions is not immediately updated after the route is processed. Using the memorysession example in the repo add the route login/{id} as shown below

# urls.nim

import prologue

import ./views


const urlPatterns* = @[
  pattern("/", hello),
  pattern("/login/", login),
  pattern("/login/{id}", login),
  pattern("/logout", logout),
  pattern("/print", print)
]

Update the login handler to actually use the path parameter like so

# view.nim

import prologue

proc hello*(ctx: Context) {.async.} =
  resp "<h1>Hello, Prologue!</h1>"

proc login*(ctx: Context) {.async.} =
  ctx.session["flywind"] = "123"
  ctx.session["ordontfly"] = "345"

  ## Be careful when using session or csrf middlewares,
  ## Response object will cover the headers of before.
  resp htmlResponse("<h1>Login</h1>" & $ctx.getPathParams("id"), headers = ctx.response.headers)

proc print*(ctx: Context) {.async.} =
  resp $ctx.session

proc logout*(ctx: Context) {.async.} =
  ctx.session.clear()
  resp htmlResponse("<h1>Logout</h1>", headers = ctx.response.headers)

Now when you run the app and now call http://localhost:8080/login/1 and then check http://localhost:8080/print as before you will see session is empty.

Route http://localhost:8080/login works just fine as before

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

No branches or pull requests

1 participant