actix / actix/actix-extras

Ability to extract SessionKey

Aperta
#306 17 commenti 4 reazioni 1 assegnatario Rivendicata da @miketwenty1 Vedi su GitHub
A-session C-feature
Lingua principale
Rust
Stelle
889
Fork
224
Merge medio
9h 37m
PR unite (30g)
20

Descrizione

### Discussed in https://github.com/actix/actix-extras/discussions/305

Originally posted by **miketwenty1** December 4, 2022
**Goal:** Prevent 1 user from having multiple active sessions.

I'm using actix-web redis session middleware.
```
.wrap(SessionMiddleware::new(
RedisActorSessionStore::new(redis_conn.clone()),
secret_key.clone(),
))
```

When a user does a login, I'll go ahead and insert some data into their session.
```
session.insert("userid", id).expect("id inserted");
```

Seemingly these key/values via the `session.insert` are inner key/values to the actual managed middleware session keys that are made automagically.

**First question:** How can I extract this middleware session id key that redis uses for the inserts/sessions?

My thought is I would go ahead and insert a the userid as a redis key with the value being the middleware redis session id so I could easily lookup and void any sessions that the user may have if logging in again. (seems hacky idk).

**Second question:** Is there a much easier/cleaner way of doing this while still getting the nice managed sessions from the redis middleware?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.