feat: add button to sign out to all connected devices

This commit is contained in:
Divlo 2022-08-29 20:15:47 +02:00
parent c4bb7c9b17
commit 38e227a9d4
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
4 changed files with 21 additions and 7 deletions

View File

@ -170,13 +170,13 @@ export const UserSettings: React.FC = () => {
} }
const handleSignout = async (): Promise<void> => { const handleSignout = async (): Promise<void> => {
try {
setFetchState('loading') setFetchState('loading')
await authentication.signoutServerSide() await authentication.signoutServerSide()
} catch (error) {
setFetchState('error')
setMessage('errors:server-error')
} }
const handleSignoutAllDevices = async (): Promise<void> => {
setFetchState('loading')
await authentication.signoutAllDevicesServerSide()
} }
const handleDeletionProvider = ( const handleDeletionProvider = (
@ -375,6 +375,11 @@ export const UserSettings: React.FC = () => {
{t('application:signout')} {t('application:signout')}
</Button> </Button>
</div> </div>
<div className='mt-4'>
<Button type='button' color='red' onClick={handleSignoutAllDevices}>
{t('application:signout-all-devices')}
</Button>
</div>
<FormState <FormState
state={fetchState} state={fetchState}
message={message != null ? t(message) : undefined} message={message != null ? t(message) : undefined}

View File

@ -25,6 +25,7 @@
"success-email-changed": "Please check your emails to confirm your new email address. You are now signed out.", "success-email-changed": "Please check your emails to confirm your new email address. You are now signed out.",
"delete": "Delete", "delete": "Delete",
"signout": "Sign out", "signout": "Sign out",
"signout-all-devices": "Sign out of all devices",
"signin-with-an-account": "Sign in with an account", "signin-with-an-account": "Sign in with an account",
"signout-with-an-account": "Sign out with an account", "signout-with-an-account": "Sign out with an account",
"success-deleted-provider": "The provider has been deleted.", "success-deleted-provider": "The provider has been deleted.",

View File

@ -25,6 +25,7 @@
"success-email-changed": "Veuillez vérifier vos emails pour confirmer votre nouvelle adresse email. Vous êtes maintenant déconnecté.", "success-email-changed": "Veuillez vérifier vos emails pour confirmer votre nouvelle adresse email. Vous êtes maintenant déconnecté.",
"delete": "Supprimer", "delete": "Supprimer",
"signout": "Se déconnecter", "signout": "Se déconnecter",
"signout-all-devices": "Se déconnecter de tous les appareils",
"signin-with-an-account": "Se connecter avec un compte", "signin-with-an-account": "Se connecter avec un compte",
"signout-with-an-account": "Se déconnecter avec un compte", "signout-with-an-account": "Se déconnecter avec un compte",
"success-deleted-provider": "Le moyen de connexion a été supprimé.", "success-deleted-provider": "Le moyen de connexion a été supprimé.",

View File

@ -112,6 +112,13 @@ export class Authentication {
this.signout() this.signout()
} }
public async signoutAllDevicesServerSide(): Promise<void> {
try {
await this.api.delete('/users/signout')
} catch {}
this.signout()
}
public signin(): void { public signin(): void {
cookies.set('refreshToken', this.tokens.refreshToken) cookies.set('refreshToken', this.tokens.refreshToken)
} }