Linked frontend to backend

This commit is contained in:
Kamigen
2024-04-22 16:38:17 -04:00
parent ec32a525a9
commit 4a74ca99b7
2 changed files with 17 additions and 3 deletions

View File

@@ -42,6 +42,18 @@ export const auth = defineStore({
this.startRefreshTokenTimer();
},
async loginGoogle(client, accessToken) {
const response = await client.post(`${baseUrl}/google`, {accessToken: accessToken})
this.user = {
accessToken: response.data.accessToken,
refreshToken: response.data.refreshToken,
email: response.data.email
}
localStorage.setItem('jwt', this.user.accessToken);
this.startRefreshTokenTimer();
},
logout() {
localStorage.setItem('jwt', '');
this.user = null;

View File

@@ -4,6 +4,7 @@
<GoogleLogin :callback="googleCallback" popup-type="TOKEN">
<button>Login Using Google</button>
</GoogleLogin>
<div class="sm:flex hidden items-center justify-between flex-col"
style="background-color: #f4f4f4; margin-top: 3%;">
@@ -105,7 +106,7 @@ import {auth} from '@/stores/auth.js';
import {ref} from 'vue';
import {useRouter} from 'vue-router';
import {useClient} from "@/plugins/api.js";
import {decodeCredential} from 'vue3-google-login'
import {GoogleLogin} from "vue3-google-login";
const api = useClient()
@@ -116,6 +117,7 @@ let user = ref({});
let errorSnackBar = ref(false);
async function login() {
// TODO: Make the store handle errors
try {
await store.login(api, user.value.email, user.value.password)
router.push('/');
@@ -125,8 +127,8 @@ async function login() {
}
const googleCallback = (response) => {
console.log(response)
//store.loginWithGoogle(api, credential)
// TODO: Make the store handle errors
store.loginGoogle(api, response["access_token"])
}
</script>