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

Added Button to Logout in Settings #68

Merged
merged 8 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion src/application/i18n/messages/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"auth": {
"login": "Login"
"login": "Login",
"logout": "Logout"
},
"settings": {
"title": "Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ interface UseOAuthComposableState {
* Shows a popup window with google authorization
*/
showGoogleAuthPopup: () => void;
/**
* Logs out the user
*/
logoutTheUser: () => Promise<void>;
}

/**
* Methods for working with OAuth (Google)
* Methods for working with Auth
*/
export default function useOAuth(): UseOAuthComposableState {
export default function useAuth(): UseOAuthComposableState {
/**
* Google OAuth URL
*/
Expand Down Expand Up @@ -54,8 +58,16 @@ export default function useOAuth(): UseOAuthComposableState {
}
});
}
/**
*Logs out the user by deleting the refresh token in local strorage
*/
async function logoutTheUser(): Promise<void> {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
await authService.logout();
}

return {
showGoogleAuthPopup,
logoutTheUser,
};
}

4 changes: 2 additions & 2 deletions src/presentation/components/header/HeaderLoginButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import { IconUser } from '@codexteam/icons';
import { useI18n } from 'vue-i18n';
import Button from '@/presentation/components/button/Button.vue';
import useOAuth from '@/application/services/useOAuth';
import useAuth from '@/application/services/useAuth';

const { t } = useI18n();
const { showGoogleAuthPopup } = useOAuth();
const { showGoogleAuthPopup } = useAuth();

/**
* Shows Google Authentication in a popup
Expand Down
26 changes: 24 additions & 2 deletions src/presentation/pages/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
<template>
<h1>{{ t('settings.title') }}</h1>
<ThemeButton />
<Button
:text="t('auth.logout')"
type="primary"
:icon="IconUnlink"
@click="logout"
/>
</template>

<script lang="ts" setup>
import { useI18n } from 'vue-i18n';
import ThemeButton from '@/presentation/components/theme/ThemeButton.vue';
import ThemeButton from '../components/theme/ThemeButton.vue';
import Button from '../components/button/Button.vue';
import { IconUnlink } from '@codexteam/icons';
import { useRouter } from 'vue-router';
import useAuth from '@/application/services/useAuth';

const { t } = useI18n();
</script>
const router = useRouter();
const { logoutTheUser } = useAuth();

/**
* Function to logout the user by deleting the refresh token from the local storage and redirecting to the main page
*/
async function logout() {
await logoutTheUser().then(() => {
router.push({ path: '/' }).then(() => {
window.location.reload();
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
});
});
}
</script>
<style scoped>
</style>