Use the attachLogoutEvent of the ushell container to trigger your approuter logout endpoint, that needs to be configured in your xs-app.json
. The code in my launchpad.html
looks like this:
<script>
sap.ui.getCore().attachInit(() => {
sap.ushell.Container.createRenderer('fiori2', true).then(renderer => renderer.placeAt("content"))
sap.ushell.Container.attachLogoutEvent(e => {
e.preventDefault()
window.location.replace('/do/logout')
}, false)
})
</script>
This way, you can reuse the default logout dialog logic the launchpad provides.
For completeness, find also my approuter configuration and custom logout page below.
My xs-app.json
:
{
"welcomeFile": "index.html",
"authenticationMethod": "route",
"logout": {
"logoutEndpoint": "/do/logout",
"logoutPage": "/logged-out.html"
},
"sessionTimeout": 60,
"routes": [
{
"source": "^/logged-out.html$",
"localDir": ".",
"authenticationType": "none"
},
{
"source": "^/launchpad.html$",
"localDir": ".",
"authenticationType": "xsuaa",
"cacheControl": "no-cache, no-store, must-revalidate"
},
{
"source": "^/appconfig/(.*)$",
"localDir": ".",
"authenticationType": "xsuaa"
},
{
"source": "^/user-api(.*)",
"target": "$1",
"service": "sap-approuter-userapi",
"authenticationType": "xsuaa"
},
...
]
}
My logged-out.html
file, placed in the approuter folder next to the launchpad.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Logged out</title>
<style>
h2 {
font-family: "Arial", sans-serif;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="centered">
<h2>You are now logged out</h2>
</div>
</body>
</html>