How do I save the user session to a website stored on AWS - S3?

Asked

Viewed 33 times

0

At AWS we may use the S3 service to provide static websites. Seundo to documentation static means not using back-end like php, Asp.net, etc.

However, I can load content dynamically through javascript get requests, consuming end-points of Apis that can be loaded asynchronously. I can upload images, videos, texts and etc.

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

Is there any way to do that?

1 answer

1

So, man, I’m gonna answer around here because I can’t comment. You will not be able to store session via API (ajax requests, etc). This is because these requests are completely independent of each other and usually the backend treats each of them as independent sessions. There are a few ways you can get around it. What I usually do is use a JWT (Json Web Token). With it you can store information about the user within it and recover them within your backend. These tokens are often used in session form, you can send an expiration date within it and renew that 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 needs to log in again. You can store this token in sessionStorage, localStorage or even use cookies.

Through S3, because it’s static, you won’t 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 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 case)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.