Hello Forum!
I would like to add a “remember me” option on my login page. I understand I have to use wix-localStorage to save the data but I don’t get the logic behind it. Does anyone know how to accomplish this?
Hello Forum!
I would like to add a “remember me” option on my login page. I understand I have to use wix-localStorage to save the data but I don’t get the logic behind it. Does anyone know how to accomplish this?
Use Wix Storage in your code, read these api pages:
http://intense-brook-61045.herokuapp.com/wix-storage.html
Wix Storage
The wix-storage module contains functionality for the persistent storage of key/value data in the user’s browser.
There are two types of storage:
Local: Data in local storage never expires, even if the user closes your page. When the user reopens the page later, the data can still be retrieved.
Session: Data in session storage is available while the user’s web session is active. The session ends when the user closes the browser tab or window. When the session ends, all the data in session storage is lost. Reloading or restoring the page does not affect session storage data.
To use the Storage API, import the needed storage type(s) from the wix-storage module:
import {local, session} from 'wix-storage';
// Or one of:
import {local} from 'wix-storage';
import {session} from 'wix-storage';
The APIs in wix-storage can only be used in front-end code.
It clearly details the difference between local and session storage and how to apply the code in the examples shown…
import {session} from 'wix-storage';
// ...
session.setItem("key", "value");
import {session} from 'wix-storage';
// ...
let value = session.getItem("key"); // "value"
Just add a simple checkbox from user input and add in the code that when the checkbox is ticked for remember me, that the item is stored in session storage and retrieved from session storage if needed.
Or another way is to use third party authentication option which will generate a session token for you and then apply the session token if everything is correct, with the code mostly written for you in this api guide:
https://www.wix.com/code/reference/wix-users-backend.html#currentUser
Have a read of these previous posts too:
https://www.wix.com/code/home/forum/community-discussion/access-login-protected-third-party-endpoint
https://www.wix.com/code/home/forum/community-discussion/google-identity-platform-oauth-2
https://www.wix.com/code/home/forum/community-discussion/google-client-api-oauth2-rawabi
https://www.wix-forum-community.com/forum/wish-list/oauth-member-login
and
https://support.wix.com/en/article/wix-code-security-considerations#api-keys