How to save the user session to a site stored in AWS - S3?

0

At AWS we can use the S3 service to provide static web sites. Seundo at documentation stands for static not using backend like php, asp.net, etc.

However, I can dynamically load content through javascript get requests, consuming end-points of APIs that can be loaded asynchronously. By uploading images, graphics, text videos and etc.

The only problem I'm encountering is how to save the user's session.

Is there any way to do this?

    
asked by anonymous 23.08.2018 / 05:11

1 answer

1

So, man, I'll answer here because I can not comment. You will not be able to store session through API (ajax requests, etc). This is because these requests are completely independent of each other and the backend usually treats each of them as independent sessions. There are a few ways you can get around this. What I usually do is use a JWT (Json Web Token) . With it you can store information about the user inside it and retrieve them inside your backend. These tokens are often used in session form, you can send an expiration date inside it and renew this expiration with each call to the backend, for example, causing if the user stays more than 20min without calling the backend, the token becomes invalid and it must log in again. You can store this token in sessionStorage, localStorage, or even use cookies.

Through S3, because it is static, you will not be able to work with sessions, since sessions usually work well on sites that are rendered by the backend itself (Django, Pyramid, among other frameworks) do this, but you you will not be able to use S3 to publish this type of site.

In short, I suggest you use JWT to work with sessions (simulate them, in that case)

    
11.09.2018 / 19:06