mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-06 18:17:38 +08:00
Expose Google client ID via API config and use dynamically
This commit is contained in:
@@ -17,7 +17,7 @@ export const API_PORT = 8081
|
|||||||
|
|
||||||
// export const API_BASE_URL = API_PORT ? `${API_DOMAIN}:${API_PORT}` : API_DOMAIN
|
// export const API_BASE_URL = API_PORT ? `${API_DOMAIN}:${API_PORT}` : API_DOMAIN
|
||||||
export const API_BASE_URL = "";
|
export const API_BASE_URL = "";
|
||||||
export const GOOGLE_CLIENT_ID = '777830451304-nt8afkkap18gui4f9entcha99unal744.apps.googleusercontent.com'
|
export const config = { googleClientId: '' }
|
||||||
export const toast = useToast()
|
export const toast = useToast()
|
||||||
|
|
||||||
initTheme()
|
initTheme()
|
||||||
@@ -32,3 +32,10 @@ checkToken().then(valid => {
|
|||||||
clearToken()
|
clearToken()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
fetch(`${API_BASE_URL}/api/config`).then(async res => {
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json()
|
||||||
|
config.googleClientId = data.googleClientId || ''
|
||||||
|
}
|
||||||
|
}).catch(() => {/* ignore */})
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
import { API_BASE_URL, GOOGLE_CLIENT_ID, toast } from '../main'
|
import { API_BASE_URL, config, toast } from '../main'
|
||||||
import { setToken, loadCurrentUser } from './auth'
|
import { setToken, loadCurrentUser } from './auth'
|
||||||
|
|
||||||
export async function googleGetIdToken() {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!window.google || !GOOGLE_CLIENT_ID) {
|
if (!window.google || !config.googleClientId) {
|
||||||
toast.error('Google 登录不可用')
|
toast.error('Google 登录不可用')
|
||||||
reject()
|
reject()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
window.google.accounts.id.initialize({
|
window.google.accounts.id.initialize({
|
||||||
client_id: GOOGLE_CLIENT_ID,
|
client_id: config.googleClientId,
|
||||||
callback: ({ credential }) => resolve(credential),
|
callback: ({ credential }) => resolve(credential),
|
||||||
use_fedcm: true
|
use_fedcm: true
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public class ConfigController {
|
|||||||
@Value("${app.ai.format-limit:3}")
|
@Value("${app.ai.format-limit:3}")
|
||||||
private int aiFormatLimit;
|
private int aiFormatLimit;
|
||||||
|
|
||||||
|
@Value("${google.client-id:}")
|
||||||
|
private String googleClientId;
|
||||||
|
|
||||||
private final RegisterModeService registerModeService;
|
private final RegisterModeService registerModeService;
|
||||||
|
|
||||||
@GetMapping("/config")
|
@GetMapping("/config")
|
||||||
@@ -43,6 +46,7 @@ public class ConfigController {
|
|||||||
resp.setCommentCaptchaEnabled(commentCaptchaEnabled);
|
resp.setCommentCaptchaEnabled(commentCaptchaEnabled);
|
||||||
resp.setAiFormatLimit(aiFormatLimit);
|
resp.setAiFormatLimit(aiFormatLimit);
|
||||||
resp.setRegisterMode(registerModeService.getRegisterMode());
|
resp.setRegisterMode(registerModeService.getRegisterMode());
|
||||||
|
resp.setGoogleClientId(googleClientId);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,5 +59,6 @@ public class ConfigController {
|
|||||||
private boolean commentCaptchaEnabled;
|
private boolean commentCaptchaEnabled;
|
||||||
private int aiFormatLimit;
|
private int aiFormatLimit;
|
||||||
private RegisterMode registerMode;
|
private RegisterMode registerMode;
|
||||||
|
private String googleClientId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user