Ensure session data is stored on the session after signup/signin

This commit is contained in:
Tobie Morgan Hitchcock 2022-09-05 00:53:35 +01:00
parent 82e347027d
commit 6f0ff853f8
2 changed files with 10 additions and 0 deletions

View file

@ -9,6 +9,7 @@ use chrono::{Duration, Utc};
use jsonwebtoken::{encode, EncodingKey}; use jsonwebtoken::{encode, EncodingKey};
use std::sync::Arc; use std::sync::Arc;
use surrealdb::sql::Object; use surrealdb::sql::Object;
use surrealdb::sql::Value;
use surrealdb::Auth; use surrealdb::Auth;
use surrealdb::Session; use surrealdb::Session;
@ -144,6 +145,10 @@ pub async fn sc(
..Claims::default() ..Claims::default()
}; };
// Set the authentication on the sesssion // Set the authentication on the sesssion
session.ns = Some(ns.to_owned());
session.db = Some(db.to_owned());
session.sc = Some(sc.to_owned());
session.sd = Some(Value::from(rid));
session.au = Arc::new(Auth::Sc(ns, db, sc)); session.au = Arc::new(Auth::Sc(ns, db, sc));
// Create the authentication token // Create the authentication token
match encode(&*HEADER, &val, &key) { match encode(&*HEADER, &val, &key) {

View file

@ -7,6 +7,7 @@ use chrono::{Duration, Utc};
use jsonwebtoken::{encode, EncodingKey}; use jsonwebtoken::{encode, EncodingKey};
use std::sync::Arc; use std::sync::Arc;
use surrealdb::sql::Object; use surrealdb::sql::Object;
use surrealdb::sql::Value;
use surrealdb::Auth; use surrealdb::Auth;
use surrealdb::Session; use surrealdb::Session;
@ -79,6 +80,10 @@ pub async fn sc(
..Claims::default() ..Claims::default()
}; };
// Set the authentication on the sesssion // Set the authentication on the sesssion
session.ns = Some(ns.to_owned());
session.db = Some(db.to_owned());
session.sc = Some(sc.to_owned());
session.sd = Some(Value::from(rid));
session.au = Arc::new(Auth::Sc(ns, db, sc)); session.au = Arc::new(Auth::Sc(ns, db, sc));
// Create the authentication token // Create the authentication token
match encode(&*HEADER, &val, &key) { match encode(&*HEADER, &val, &key) {