mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-25 23:50:51 +08:00
Expose Google client ID via API config and use dynamically
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
import { API_BASE_URL, GOOGLE_CLIENT_ID, toast } from '../main'
|
||||
import { API_BASE_URL, config, toast } from '../main'
|
||||
import { setToken, loadCurrentUser } from './auth'
|
||||
|
||||
export async function googleGetIdToken() {
|
||||
if (!config.googleClientId) {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE_URL}/api/config`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
if (data.googleClientId) {
|
||||
config.googleClientId = data.googleClientId
|
||||
}
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!window.google || !GOOGLE_CLIENT_ID) {
|
||||
if (!window.google || !config.googleClientId) {
|
||||
toast.error('Google 登录不可用')
|
||||
reject()
|
||||
return
|
||||
}
|
||||
window.google.accounts.id.initialize({
|
||||
client_id: GOOGLE_CLIENT_ID,
|
||||
client_id: config.googleClientId,
|
||||
callback: ({ credential }) => resolve(credential),
|
||||
use_fedcm: true
|
||||
use_fedcm: true
|
||||
})
|
||||
window.google.accounts.id.prompt()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user