I’m constructing a PWA with React (frontend) and Node.js/Specific (backend).
On login, I save a JWT token in localStorage. I additionally tried utilizing cookies with cookie-parser
and express-session
.
This works high-quality in Android/Chrome:
- After I add the app to the house display, open it once more later, the login session remains to be legitimate.
However in iOS Safari (PWA added to residence display):
-
After logging in, the token is seen in
localStorage
inside Safari. -
However once I launch the app from the house display, the token is lacking and the person is logged out.
Minimal Instance
Frontend (React)
// login.js
perform login() {
fetch('/api/login', { methodology: 'POST' })
.then(res => res.json())
.then(({ token }) => {
localStorage.setItem('token', token);
});
}
// app.js
const token = localStorage.getItem('token');
console.log('Token on load:', token);
Backend (Node.js/Specific)
const categorical = require('categorical');
const cookieParser = require('cookie-parser');
const app = categorical();
app.use(cookieParser());
app.publish('/api/login', (req, res) => {
const token = 'abc123'; // faux for instance
res.cookie('token', token, { httpOnly: true });
res.json({ token });
});
app.hear(3000);
Drawback
-
In iOS Safari PWA home-screen mode, the session/token doesn’t persist.
-
In Android Chrome, it really works as anticipated.
Query
-
Is there any option to persist login/session when an iOS PWA is opened from the house display?
-
If not, what’s the beneficial workaround?