Jelajahi Sumber

add sending google access token to api

tomoya 2 tahun lalu
induk
melakukan
5c4c4ef73a
3 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 4 1
      frontend/src/api.ts
  2. 11 0
      frontend/src/stores/main.ts
  3. 1 0
      frontend/src/views/Login.vue

+ 4 - 1
frontend/src/api.ts

@@ -67,5 +67,8 @@ export const api = {
   },
   async getVideos(token: string) {
     return axios.get<Video[]>(`${apiUrl}/api/v1/videos/`, authHeaders(token));
-  }
+  },
+  async googleLogin(access_token: string){
+    return axios.post(`${apiUrl}/api/v1/login/google/access-token`, {access_token:access_token})
+  },
 };

+ 11 - 0
frontend/src/stores/main.ts

@@ -6,6 +6,7 @@ import { getLocalToken, removeLocalToken, saveLocalToken } from "@/utils";
 import type { AppNotification } from '@/interfaces';
 import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState, Video, VideoCreate } from '@/interfaces';
 import i18n from '@/plugins/i18n'
+import { GoogleLogin } from "vue3-google-login";
 
 const defaultState: MainState = {
   isLoggedIn: null,
@@ -265,6 +266,16 @@ export const useMainStore = defineStore("MainStoreId", {
         await mainStore.checkApiError(error);
       }
     },
+    async googleLogin(access_token:string) {
+      try{
+        const response = await api.googleLogin(access_token)
+        if (response) {
+          console.log(response)
+        }
+      } catch (error) {
+        await this.checkApiError(error)
+      }
+    }
   }
 });
 

+ 1 - 0
frontend/src/views/Login.vue

@@ -23,6 +23,7 @@ const handleGoogleAccessTokenLogin = () => {
     data.value = response;
     saveLocalToken(response.access_token);
     mainStore.setToken(response.access_token);
+    mainStore.googleLogin(response.access_token);
   });
 };