ixhbinphoenix / actix-session-surrealdb

http://crates.io/crates/actix-session-surrealdb
MIT License
9 stars 1 forks source link

session_ttl_policy not a thing???? #7

Closed CheetoTrump closed 9 months ago

CheetoTrump commented 9 months ago

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(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.

CheetoTrump commented 9 months ago

https://pastebin.com/X657eTd9

better view of the code since github of all things dosnt have the code block working

CheetoTrump commented 9 months ago

my toml imports:

rand = "0.8.5" serde = { version = "1.0.196", features = ["derive"] } surrealdb = "1.1.1" tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] } actix-web = "4.4.1" actix-session-surrealdb = "0.1.8" actix-session = "0.9.0"

CheetoTrump commented 9 months ago

it seems the docs.rs has the mostly correct code but the github and crates.io examples seem to be outdated/incorrect