ixhbinphoenix / actix-session-surrealdb Goto Github PK
View Code? Open in Web Editor NEWHome Page: http://crates.io/crates/actix-session-surrealdb
License: MIT License
Home Page: http://crates.io/crates/actix-session-surrealdb
License: MIT License
in both the readme and crate docs you have this snippet:
HttpServer::new(move || {
App::new()
.wrap(
SessionMiddleware::builder(session_store.clone(), Key::generate())
this is very subtly incorrect as it will generate a different key for each server worker
please amend it to
let key = Key::generate();
HttpServer::new(move || {
App::new()
.wrap(
SessionMiddleware::builder(session_store.clone(), key.clone())
and publish a new release so users of this crate can copy-paste from the updated crates.io page
Hey, sorry, it's me again. I've been trying to use actix-session 0.8.0, and it seems as if another breaking change has occurred where the implementation for SessionStore has changed. I've checked the documentation for the trait before and after and cannot see any breaking changes or anything, but I'm not sure. I just know that this error goes away after downgrading to 0.7.2.
Sorry for bothering you, and no rush; I can just use actix-identity 0.7.2, but I just wanted to make you aware.
I'm getting unexpected errors when building actix-session-surrealdb on version 0.1.5. Could it be that I am using SurrealDB 1.0.0 and the version had some breaking changes?
Here are the compile errors I am getting below:
error[E0308]: mismatched types
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:158:32
|
158 | ..._: KeyRecord = self.client.delete(thingy).await.expect("Deleting database record failed!...
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected KeyRecord
, found Option<_>
| |
| expected due to this
|
= note: expected struct KeyRecord
found enum std::option::Option<_>
error[E0308]: mismatched types
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:177:56
|
177 | let res: Result<KeyRecord, surrealdb::Error> = self
| ______________________________________^
178 | | .client
179 | | .create(self.tb.clone())
180 | | .content(KeyRecord {
... |
187 | | })
188 | | .await;
| |^ expected Result<KeyRecord, ...>
, found Result<Vec<_>, Error>
|
= note: expected enum Result<KeyRecord, _>
found enum Result<Vec<_>, _>
error[E0308]: mismatched types
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:220:56
|
220 | ...::Error> = self.client.update(thingy).merge(updated).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected Result<KeyRecord, ...>
, found Result<Option<...>, ...>
|
= note: expected enum Result<KeyRecord, _>
found enum Result<std::option::Option<_>, _>
error[E0308]: mismatched types
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:237:13
|
237 | ... self.client.delete(thingy).await.map_err(|_| anyhow!("Failed to delete database record"))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected Result<(), Error>
, found Result<Option<...>, ...>
|
= note: expected enum Result<(), _>
found enum Result<std::option::Option<_>, _>
note: return type inferred to be Result<(), anyhow::Error>
here
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:229:95
|
229 | async fn update_ttl(&self, session_key: &SessionKey, ttl: &Duration) -> Result<(), Error> {
| __________________________________________________________________________________________^
230 | | let id = session_key.as_ref().to_owned();
231 | | let thingy = Thing {
232 | | tb: self.tb.clone(),
... |
252 | | }
253 | | }
| |^
error[E0308]: mismatched types
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:251:13
|
251 | ... self.client.update(thingy).merge(updated).await.map_err(|_| anyhow!("Failed to update database record"))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected Result<(), Error>
, found Result<Option<...>, ...>
|
= note: expected enum Result<(), _>
found enum Result<std::option::Option<_>, _>
note: return type inferred to be Result<(), anyhow::Error>
here
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-session-surrealdb-0.1.5/src/lib.rs:229:95
|
229 | async fn update_ttl(&self, session_key: &SessionKey, ttl: &Duration) -> Result<(), Error> {
| __________________________________________________________________________________________^
230 | | let id = session_key.as_ref().to_owned();
231 | | let thingy = Thing {
232 | | tb: self.tb.clone(),
... |
252 | | }
253 | | }
| |^
For more information about this error, try rustc --explain E0308
.
error: could not compile actix-session-surrealdb
(lib) due to 5 previous errors
So i took your example off of github and during compile i get these errors,
error: comparison operators cannot be chained
--> src\main.rs:3:26
|
3 | let db = Surreal::new("127.0.0.1:8000").await.unwrap();
| ^ ^
|
help: use ::<...>
instead of <...>
to specify lifetime, type, or const arguments
|
3 | let db = Surreal::new::("127.0.0.1:8000").await.unwrap();
| ++
error: expected one of ;
or else
, found .
--> src\main.rs:3:48
|
3 | let db = Surreal::new("127.0.0.1:8000").await.unwrap();
| ^ expected one of ;
or else
error: unexpected token, expected ;
--> src\main.rs:6:13
|
6 | user: "root",
| ^
error[E0433]: failed to resolve: use of undeclared crate or module io
--> src\main.rs:2:20
|
2 | async fn main() -> io::Result<()> {
| ^^ use of undeclared crate or module io
|
help: a builtin type with a similar name exists
|
2 | async fn main() -> i8::Result<()> {
| ~~
help: consider importing one of these items
|
1 + use std::io;
|
1 + use tokio::io;
|
error[E0752]: main
function is not allowed to be async
--> src\main.rs:2:1
|
2 | async fn main() -> io::Result<()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ main
function is not allowed to be async
Some errors have detailed explanations: E0433, E0752.
For more information about an error, try rustc --explain E0433
.
from there i made the suggested edits:
added std::io, changed
let db = Surreal::new("127.0.0.1:8000").await.unwrap();
to
let db = Surreal::new::("127.0.0.1:8000").await.unwrap();
`use actix_web::cookie::time::Duration;
use actix_web::cookie::Key;
use surrealdb::opt::auth::Root;
use std::io;
use surrealdb::Surreal;
use surrealdb::engine::remote::ws::Ws;
use actix_web::HttpServer;
use actix_web::App;
use actix_session::SessionMiddleware;
use actix_session::config::PersistentSession;
use actix_session_surrealdb::SurrealSessionStore;
#[actix_web::main]
async fn main() -> io::Result<()> {
let db = Surreal::new::("127.0.0.1:8000").await.unwrap();
db.signin(Root {
username: "myuser",
password: "mypass",
})
.await.unwrap();
db.use_ns("test").use_db("test").await.unwrap();
let session_store = SurrealSessionStore::from_connection(db, "sessions");
let key = Key::generate();
HttpServer::new(move || {
App::new()
.wrap(
SessionMiddleware::builder(session_store.clone(), key.clone())
.cookie_same_site(actix_web::cookie::SameSite::None)
.cookie_secure(true)
.cookie_http_only(true)
.session_lifecycle(
PersistentSession::default()
.session_ttl_policy(actix_session::config::TtlExtensionPolicy::OnStateChanges)
.session_ttl(Duration::days(7)),
)
.build()
)
})
.bind(("127.0.0.1", "8080"))?
.run()
.await
}`
current code^^^^
i get these errors
error[E0599]: no method named session_ttl_policy
found for struct actix_session::config::PersistentSession
in the current scope
--> src\main.rs:39:30
|
38 | / PersistentSession::default()
39 | | .session_ttl_policy(actix_session::config::TtlExtensionPolicy::OnStateChanges)
| | -^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: session_ttl
| |_____________________________|
|
error[E0277]: the trait bound (&str, &str): ToSocketAddrs
is not satisfied
--> src\main.rs:45:11
|
45 | .bind(("127.0.0.1", "8080"))?
| ---- ^^^^^^^^^^^^^^^^^^^^^ the trait ToSocketAddrs
is not implemented for (&str, &str)
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait ToSocketAddrs
:
(std::string::String, u16)
(IpAddr, u16)
(Ipv4Addr, u16)
(Ipv6Addr, u16)
(&str, u16)
note: required by a bound in HttpServer::<F, I, S, B>::bind
--> C:\Users\xboxk.cargo\registry\src\index.crates.io-1cd66030c949c28d\actix-web-4.4.1\src\server.rs:382:20
|
382 | pub fn bind<A: net::ToSocketAddrs>(mut self, addrs: A) -> io::Result {
| ^^^^^^^^^^^^^^^^^^ required by this bound in HttpServer::<F, I, S, B>::bind
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try rustc --explain E0277
.
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.