B4J Question Keep the same session id

TomDuncan

Active Member
Licensed User
Longtime User
I want to use cookies with my program.
I can add the cookie and save this for logging in.
However when I restart the server I loose the session I'd. Well I think that is what happens.
How can I get around this.
I would like the person to be automatically logged in when they log into my all new forum.

Tom
 

Roycefer

Well-Known Member
Licensed User
Longtime User
The server can issue the session an access token stored in a cookie once that session had logged in. That same access token is stored on the server in a database or KeyValueStore. You can check for the presence of a valid token in a Filter. If the server is restarted, the database or KeyValueStore will remain intact, with the list of valid access tokens.
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
I am using this to set the cookie.
It seems to work.
B4X:
                    ws.Session.SetAttribute("forumname",a(0))
Where can I get this token?
and what do I then do.
Sorry to be such a beginner at this.

Tom
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Yeah, what he said.

An access token can be anything. Like a randomly generated 6 digit number, for instance. Store it in a database or a KeyValueStore (something that will persist past a server restart). When a user logs in, set a Cookie with token=123456 (or whatever) and then you can check to see if that Cookie's token value is in your database whenever that user comes back to your site.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…