chore: update readme

This commit is contained in:
Björn Fromme
2026-08-12 09:23:44 +02:00
parent b62abb1801
commit b9edc98074
+19 -10
View File
@@ -101,36 +101,36 @@ Sessions are stored via Symfony's filesystem cache by default (`config/packages/
## Appsmith app integration ## Appsmith app integration
Create a shared module with this js: Create a shared module with this js. It stays generic — every app key and page name is passed in by the caller, so the same code can be dropped into every app unchanged:
```js ```js
export default { export default {
isLoggedIn() { isLoggedIn() {
return !!appsmith.store.sid; return !!appsmith.store.sid;
}, },
login(appKey) { login({ app }) {
navigateTo(`https://bff.ep-reisen.net/auth/login?app=${appKey}`, {}, 'SAME_WINDOW'); navigateTo(`https://bff.ep-reisen.net/auth/login?app=${app}`, {}, 'SAME_WINDOW');
}, },
async checkReturningFromLogin(loginPageName, protectedPageName) { async checkReturningFromLogin({ loginPage, protectedPage }) {
const sid = appsmith.URL.queryParams.sid; const sid = appsmith.URL.queryParams.sid;
const error = appsmith.URL.queryParams.error; const error = appsmith.URL.queryParams.error;
if (error === 'access_denied') { if (error === 'access_denied') {
showAlert('You do not have access to this app.', 'error'); showAlert('You do not have access to this app.', 'error');
navigateTo(loginPageName, {}, 'SAME_WINDOW'); navigateTo(loginPage, {}, 'SAME_WINDOW');
return; return;
} }
if (sid) { if (sid) {
await storeValue('sid', sid); await storeValue('sid', sid);
navigateTo(protectedPageName, {}, 'SAME_WINDOW'); navigateTo(protectedPage, {}, 'SAME_WINDOW');
} }
if (appsmith.store.sid && !appsmith.store.user) { if (appsmith.store.sid && !appsmith.store.user) {
const profile = await Bff_Me.run(); const profile = await Bff_Me.run();
await storeValue('user', profile); await storeValue('user', profile);
} }
}, },
guardPage(loginPageName) { guardPage({ loginPage }) {
if (!this.isLoggedIn()) { if (!this.isLoggedIn()) {
navigateTo(loginPageName, {}, 'SAME_WINDOW'); navigateTo(loginPage, {}, 'SAME_WINDOW');
} }
}, },
async logout() { async logout() {
@@ -142,26 +142,35 @@ export default {
} }
``` ```
The per-page objects below are where an app's own configuration lives — page names and the app key. They can't be folded into the shared module: JS Objects are page-scoped and "Run on page load" applies to the page the object belongs to, so each page needs its own.
On the login page add this js to be executed onLoad: On the login page add this js to be executed onLoad:
```js ```js
export default { export default {
onLoad() { onLoad() {
return Bff.checkReturningFromLogin('Login', 'ProtectedPage'); return Bff.checkReturningFromLogin({
loginPage: 'Login',
protectedPage: 'ProtectedPage',
});
} }
} }
``` ```
Bind the login button's onClick to `{{ Bff.login({ app: 'app-sandbox' }) }}` — the same app key the `Bff_Me` query sends as `?app=`.
On the protected page add this js to be execute onLoad: On the protected page add this js to be execute onLoad:
```js ```js
export default { export default {
onLoad() { onLoad() {
return Bff.guardPage('Login'); return Bff.guardPage({ loginPage: 'Login' });
} }
} }
``` ```
Note `guardPage` only checks that a `sid` exists, not that it's still valid — an expired session surfaces on the first API call's 401 handler.
Login state can be used to toggle visibility of UI elements in Appsmith with Login state can be used to toggle visibility of UI elements in Appsmith with
```js ```js