guruahn / vue3-google-oauth2-front-sample

vue3환경에서의 vue-google-oauth2 테스트.
MIT License
20 stars 17 forks source link

Using it in Composition API #4

Open Nizzy94 opened 3 years ago

Nizzy94 commented 3 years ago

Is there a way to use it in the composition API? from the coding example, it was used in the Options API and I had to combine it with the composition API.

Leizhenpeng commented 2 years ago

https://www.npmjs.com/package/vue3-google-auth?activeTab=readme

astarrh commented 2 years ago

What is written in the docs (linked) didn't work until I made this correction:

import gAuth from 'vue3-google-auth'
const $gAuth = gAuth.useGAuth()

Edit: Nevermind. Console is still saying it is not a function. Updating above to match the docs.

astarrh commented 2 years ago

This is the error that appears in console when trying to invoke gAuth.useGAuth:

vue3_google_oauth2__WEBPACK_IMPORTED_MODULE_5__.default.useGAuth is not a function

It should be noted that the linked docs are for an older version and the current version's NPM documentation has omitted the instructions for calling the GAuth methods during setup(). It's pretty important to have access to everything in setup() as often it is necessary to make sure login issues are handled before the rest of the app tries to make it's backend server requests on page load. This is a good example of why mixing the composition and options APIs is considered an anti-pattern.

ghost commented 1 year ago

import { getCurrentInstance, onMounted } from 'vue' const { proxy } = getCurrentInstance() proxy.$gAuth.getAuthCode()