Non-Logged in Users in .init()
Introduction
In .init(), if username=null, the flow below determines how Socratease proceeds. There are two further parameters in the session_authentication key that determine how Socratease handles such sessions:
- With allow_unauthenticated_sessions=false, the Socratease library will return a 401 error
- With remember_unauthenticated_sessions=true, even if the user closes tabs or the browser when they load your property, Socratease will restore their session.
Code
const payload = {
'username': null,
'session_authentication': {
'allow_unauthenticated_sessions': true,
'remember_unauthenticated_sessions': false
}
}The Flow
graph TD;
A{username=null?}
A --> |No | A1[Create/load user with given username]
A1 --> G[return is_registered=true]
G --> B[Store jwt inside React]
A --> |Yes | C{allowUnauthenticatedSessions?}
C --> |No | D[Return 401]
C --> |Yes | E[Create user with random username]
E --> I[returns is_registered=false]
I --> J{rememberUnauthenticatedSessions?}
J --> |Yes | K[Store jwt as cookie]
J --> |No |H1[Store jwt as sessionVariable]