next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Persist Data on Auth

Open epileftro85 opened this issue 8 years ago • 6 comments

Hi, there is any way to persist the data on refresh page? i am looking with no luck, the last resort is asking here. thanks in advance.

epileftro85 avatar Jan 10 '18 23:01 epileftro85

You might want to use localstorage if you want to persist data on a page refresh. Especially when dealing with auth tokens. LocalForage is create for this. It uses the available best method for saving to localstorage.

timothyis avatar Jan 10 '18 23:01 timothyis

Cookies might be a better shout if you want them on initial request to perform server side renders.

When you use cookies they are attached to the request, whereas local storage requires you wait for the page and javascript to be loaded, parsed and executed then the requests made.

lededje avatar Jan 11 '18 13:01 lededje

Cookie is better if SSR auth is necessary.

tz5514 avatar Jan 12 '18 05:01 tz5514

Cookies are the way to go. https://www.npmjs.com/package/next-cookies might help.

timneutkens avatar Jan 13 '18 10:01 timneutkens

@epileftro85 You can checkout our boilerplate: https://arefaslani.github.io/next-boilerplate it's already configured to read and write cookies on server and client. Also it provides many options configured with Next.

arefaslani avatar Jan 13 '18 13:01 arefaslani

@arefaslani i will take a look on it, thanks

epileftro85 avatar Jan 13 '18 14:01 epileftro85