Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(user): Can Sign-out from all devices #14

Merged
merged 3 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/service/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ axios.interceptors.response.use(
}
}

// User not found.
if (errCode === 40106) {
// User not found or force logout.
if (errCode === 40106 || errCode === 40102) {
return userService.logoutAndRedirect();
}

Expand Down
3 changes: 3 additions & 0 deletions src/theme/base/_typography.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
text-decoration-line: none;
}
1 change: 1 addition & 0 deletions src/theme/main.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "variables";

@import "base/body";
@import "base/typography";
@import "base/utilities";
@import "base/color-modes";

Expand Down
8 changes: 4 additions & 4 deletions src/utilities/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export async function simpleConfirm(title: string, text?: string): Promise<boole
message: text,
buttons: [
{
text: '取消',
text: 'Cancel',
handler: () => {
resolve(false);
},
},
{
text: '確定',
text: 'OK',
handler: () => {
resolve(true);
},
Expand All @@ -72,14 +72,14 @@ export async function simpleActionSheetConfirm(
header: title,
buttons: [
{
text: buttons[0] || '確定',
text: buttons[0] || 'OK',
role: 'destructive',
handler: () => {
resolve(true);
},
},
{
text: buttons[1] || '取消',
text: buttons[1] || 'Cancel',
role: 'cancel',
handler: () => {
resolve(false);
Expand Down
40 changes: 39 additions & 1 deletion src/views/options/ProfilePage.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<script setup lang="ts">

import MainLayout from '@/components/layout/MainLayout.vue';
import apiClient from '@/service/api-client';
import exportService from '@/service/export-service';
import importService from '@/service/import-service';
import userDeleteService from '@/service/user-delete-service';
import userService from '@/service/user-service';
import { userStorage } from '@/store/main-store';
import { faDownload, faEnvelope, faTrash, faUpload } from '@fortawesome/free-solid-svg-icons';
import { simpleConfirm } from '@/utilities/alert';
import { useLoadingOverlay } from '@/utilities/loading';
import {
faDownload,
faEnvelope,
faSignOut,
faTrash,
faUpload,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IonItem, IonLabel, IonList, IonListHeader, IonNote } from '@ionic/vue';

Expand All @@ -22,6 +32,23 @@ async function exportAccounts() {
async function deleteAccount() {
await userDeleteService.deleteMeAndLogout();
}

async function sessionsRefresh() {
const v = await simpleConfirm(
'This will sign your all devices out.',
'You must re-login this device.'
);

if (!v) {
return;
}

const { run } = await useLoadingOverlay('Refreshing and Logout...');

const res = await run(() => apiClient.post('user/sessions/refresh'));

await userService.logoutAndRedirect();
}
</script>

<template>
Expand All @@ -40,6 +67,17 @@ async function deleteAccount() {
</ion-label>
</ion-item>

<!-- sessions Refresh -->
<ion-item button @click="sessionsRefresh">
<FontAwesomeIcon :icon="faSignOut" slot="start" />
<ion-label>
<h4>Sign-Out from All My Devices</h4>
<ion-note>
Make all session tokens expired, you must re-login again.
</ion-note>
</ion-label>
</ion-item>

<!-- Import -->
<ion-item button @click="importAccounts">
<FontAwesomeIcon :icon="faUpload" slot="start" />
Expand Down