#85 universal login across locales - logout

This commit is contained in:
Avris 2021-08-23 09:43:23 +02:00
parent f8e042d91d
commit 41e141b917
3 changed files with 28 additions and 1 deletions

View File

@ -1,5 +1,17 @@
<template>
<section>
<section v-if="logoutInProgress">
<p class="text-center">
<Spinner size="5rem"/>
</p>
<div>
<iframe v-for="domain in universalDomains"
:src="`${domain}/api/user/logout-universal`"
style="width: 1px; height: 1px; opacity: .01"
>
</iframe>
</div>
</section>
<section v-else>
<div class="card mb-3">
<div class="card-body d-flex flex-column flex-md-row">
<div class="mx-2 text-center">
@ -162,6 +174,8 @@
captchaToken: null,
universalDomains: process.env.ALL_LOCALES_URLS.split(',').filter(x => x !== process.env.BASE_URL),
logoutInProgress: false,
}
},
async mounted() {
@ -242,8 +256,13 @@
}
},
logout() {
this.logoutInProgress = true;
setTimeout(this.doLogout, 3000);
},
doLogout() {
this.$store.commit('setToken', null);
this.$cookies.removeAll();
this.logoutInProgress = false;
},
setProfiles(profiles) {
this.profiles = profiles;

View File

@ -19,6 +19,7 @@ const allVersionsUrls = buildList(function*() {
yield 'http://pronouns.test:3000';
yield 'http://localhost:3000';
} else {
yield 'https://pronouns.page';
for (let loc in locales) {
yield locales[loc].url;
}

View File

@ -468,6 +468,7 @@ router.post('/user/set-avatar', handleErrorAsync(async (req, res) => {
}));
router.get('/user/init-universal/:token', handleErrorAsync(async (req, res) => {
res.header('Access-Control-Allow-Origin', '*');
if (req.user) {
return res.json('Already logged in');
}
@ -476,4 +477,10 @@ router.get('/user/init-universal/:token', handleErrorAsync(async (req, res) => {
return res.json('Token saved');
}));
router.get('/user/logout-universal', handleErrorAsync(async (req, res) => {
res.header('Access-Control-Allow-Origin', '*');
res.clearCookie('token');
return res.json('Token removed');
}));
export default router;