actix / actix/actix-extras

Ability to extract SessionKey

Offen
#306 17 Kommentare 4 Reaktionen 1 zugewiesene Person Beansprucht von @miketwenty1 Auf GitHub ansehen
A-session C-feature
Vorherrschende Sprache
Rust
Sterne
889
Forks
224
Ø Merge
9 Std. 37 Min.
Gemergte PRs (30 T.)
20

Beschreibung

### 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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.