Linked frontend to backend
This commit is contained in:
@@ -42,6 +42,18 @@ export const auth = defineStore({
|
|||||||
this.startRefreshTokenTimer();
|
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() {
|
logout() {
|
||||||
localStorage.setItem('jwt', '');
|
localStorage.setItem('jwt', '');
|
||||||
this.user = null;
|
this.user = null;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<GoogleLogin :callback="googleCallback" popup-type="TOKEN">
|
<GoogleLogin :callback="googleCallback" popup-type="TOKEN">
|
||||||
<button>Login Using Google</button>
|
<button>Login Using Google</button>
|
||||||
</GoogleLogin>
|
</GoogleLogin>
|
||||||
|
|
||||||
<div class="sm:flex hidden items-center justify-between flex-col"
|
<div class="sm:flex hidden items-center justify-between flex-col"
|
||||||
style="background-color: #f4f4f4; margin-top: 3%;">
|
style="background-color: #f4f4f4; margin-top: 3%;">
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ import {auth} from '@/stores/auth.js';
|
|||||||
import {ref} from 'vue';
|
import {ref} from 'vue';
|
||||||
import {useRouter} from 'vue-router';
|
import {useRouter} from 'vue-router';
|
||||||
import {useClient} from "@/plugins/api.js";
|
import {useClient} from "@/plugins/api.js";
|
||||||
import {decodeCredential} from 'vue3-google-login'
|
import {GoogleLogin} from "vue3-google-login";
|
||||||
|
|
||||||
const api = useClient()
|
const api = useClient()
|
||||||
|
|
||||||
@@ -116,6 +117,7 @@ let user = ref({});
|
|||||||
let errorSnackBar = ref(false);
|
let errorSnackBar = ref(false);
|
||||||
|
|
||||||
async function login() {
|
async function login() {
|
||||||
|
// TODO: Make the store handle errors
|
||||||
try {
|
try {
|
||||||
await store.login(api, user.value.email, user.value.password)
|
await store.login(api, user.value.email, user.value.password)
|
||||||
router.push('/');
|
router.push('/');
|
||||||
@@ -125,8 +127,8 @@ async function login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const googleCallback = (response) => {
|
const googleCallback = (response) => {
|
||||||
console.log(response)
|
// TODO: Make the store handle errors
|
||||||
//store.loginWithGoogle(api, credential)
|
store.loginGoogle(api, response["access_token"])
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user