gofiber / session Goto Github PK
View Code? Open in Web Editor NEW⚠ Deprecated, available within Fiber v2
Home Page: https://github.com/gofiber/fiber/tree/master/middleware/session
License: MIT License
⚠ Deprecated, available within Fiber v2
Home Page: https://github.com/gofiber/fiber/tree/master/middleware/session
License: MIT License
I am working with fiber golang framework. I can't figure out why I cannot get the value set in the store(Redis in this case) from another request or within. Below is the code:
sessionProvider := redis.New(redis.Config{
KeyPrefix: "session",
Addr: "127.0.0.1:6379",
PoolSize: 8,
IdleTimeout: 30 * time.Second,
})
sessions := session.New(session.Config{
Provider: sessionProvider,
})
// sample routes for testing session
app.Get("/testing1", func(c *fiber.Ctx) {
store := sessions.Get(c)
// set value to the session store
store.Set("name", "King Windrol")
store.Save()
})
app.Get("/testing2", func(c *fiber.Ctx) {
store := sessions.Get(c)
c.Send(store.Get("name"))
})
I've tried to get it from within the same request, it seems to work just before calling store.Save() but not working after! it just returns nil
I have set the session, but whenever I try to get the session from my handlers, it returns nil. But if I go to the browser > Storage > Cookies, it's there
I can't seem to get sessions to be destroyed or regenerated. I've tried both memcache and mysql but store.Destroy()
and store.Regenerate()
aren't doing anything that I can tell. Am I doing something wrong?
Mac OSX : 10.15.4
Fiber : v1.12.0
Fiber Session : v1.2.1
I need to set no expiration session, but config always reset it to 12 * time.Hour,
for now, i just remove this line
Lines 85 to 87 in f685507
I have set the session, but whenever I try to get the session from my handlers, it returns nil. But if I go to the browser > Storage > Cookies, it's there
Hello,
Are you able to enable SetSessionID() like it is in github.com/fasthttp/session?
I've tried use session to store some data. But it seems data are not stored among different requests. Is it implementation issue or usage issue?
A simple use case is:
package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/session"
"github.com/gofiber/session/provider/sqlite3"
)
func main(){
app := fiber.New()
provider := sqlite3.New(sqlite3.Config{
DBPath: "session.db",
TableName: "session",
})
sessions := session.New(session.Config{
Provider: provider,
})
app.Get("/get", func(c *fiber.Ctx) {
store := sessions.Get(c)
defer store.Save()
id,ok := store.Get("id").(int)
if ok {
c.Send("id=",id)
store.Set("id",id+1)
}else{
c.Send("id empty, in session:",store.ID())
store.Set("id",1)
}
})
app.Listen(8060)
}
And when use browser to reload "http://url/get", I expect the id to be increment while session ID keeps the same.
Actual result is id always empty, and session ID keeps the same.
I also tried redis provider, the result is the same.
Am I use the API correctly? Or is there anything wrong with the implementation?
Hi Fenny, I want to ask you some questions about session.
I implemented some part of code wrapping that and tested using Postgres and built Save and Get methods to use. If it's same way you are going, I will make PR and wish this helps your hardworking on fiber packages.
Dear Team:
First all According to old version gofiber/session(v1.2.5) "Destroy" function is working fine. But when we upgrade to v2.0.2, "Destroy" function has been change, and if we still follow Example from README.md "Destroy" function will not working to "delete storage + cookie".
In our research, we find out the issue maybe is "Destroy" function itself has not been "Reset" dict data any more. So when we call "Save" function the dict data has been store back.
So we are very confused about it, are we missing something? Or this issue will be fix?
B.R & Tks.
Gordon
For some reason, the new version of Session panics with sqlite3 driver, although the example code has not changed.
go run main.go
2 timespackage main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/session"
"github.com/gofiber/session/provider/sqlite3"
)
func main() {
app := fiber.New()
provider := sqlite3.New(sqlite3.Config{
DBPath: "test.db",
TableName: "session",
})
sessions := session.New(session.Config{
Provider: provider,
})
app.Get("/", func(c *fiber.Ctx) {
store := sessions.Get(c)
defer store.Save()
c.Send(store.ID())
})
app.Listen(3001)
}
2020/07/21 00:31:42 session error: session: sqlite3 index last_active already exists; provider: sqlite3;
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x40 pc=0x13721e5]
goroutine 1 [running]:
github.com/fasthttp/session/v2/providers/sqlite3.(*Provider).NeedGC(0x0, 0xc0000ce820)
<autogenerated>:1 +0x5
github.com/fasthttp/session/v2.(*Session).SetProvider(0xc000582000, 0x1637700, 0x0, 0x1, 0x1)
C:/Users/mysh/go/pkg/mod/github.com/fasthttp/session/[email protected]/session.go:64 +0x51
github.com/gofiber/session.New(0xc0004a7f10, 0x1, 0x1, 0x0)
C:/Users/mysh/go/pkg/mod/github.com/gofiber/[email protected]/session.go:148 +0x533
main.main()
C:/Users/mysh/go/src/sqliteSessionsBug/main.go:17 +0x135
exit status 2
It appears that calling:
store := session.Get(c).Destroy()
Does not work well with the postgres driver and also it does not follow the signature from the original function which returns an error.
Hi,
It seems my session is not being saved, question is am I doing this right? I am not entirely sure so here's a little more context.
I am implementing a simple session-based login like this:
storage := sqlite3.New()
store := session.New(session.Config{
Storage: storage,
})
then I save it
sess.Set("email", "[email protected]")
defer sess.Save()
and then I try to read the value:
email := sess.Get("email")
log.Println(email)
log.Println(sess.Keys())
So my first question is: am I doing it right?
How would i go about saving a reference to the mongo connection in essence caching the connection and not having to make the call every time?
client, err := getMongoDbConnection(credentials)
store.Set("mongoRef", client)
err = store.Save()
fmt.Println(store.Get("mongoRef")
fmt.Println(err)
>>>>
<nil>
msgp: type "mongo.Client" not supported at D/2/Value
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.