mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 22:08:38 +00:00
fix: Try to fix login error "already logged in" issue
This commit is contained in:
@@ -231,8 +231,22 @@ export async function getOAuthState() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function onDiscordOAuthClicked(client_id) {
|
||||
const state = await getOAuthState();
|
||||
async function prepareOAuthState(options = {}) {
|
||||
const { shouldLogout = false } = options;
|
||||
if (shouldLogout) {
|
||||
try {
|
||||
await API.get('/api/user/logout', { skipErrorHandler: true });
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
localStorage.removeItem('user');
|
||||
updateAPI();
|
||||
}
|
||||
return await getOAuthState();
|
||||
}
|
||||
|
||||
export async function onDiscordOAuthClicked(client_id, options = {}) {
|
||||
const state = await prepareOAuthState(options);
|
||||
if (!state) return;
|
||||
const redirect_uri = `${window.location.origin}/oauth/discord`;
|
||||
const response_type = 'code';
|
||||
@@ -242,8 +256,13 @@ export async function onDiscordOAuthClicked(client_id) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function onOIDCClicked(auth_url, client_id, openInNewTab = false) {
|
||||
const state = await getOAuthState();
|
||||
export async function onOIDCClicked(
|
||||
auth_url,
|
||||
client_id,
|
||||
openInNewTab = false,
|
||||
options = {},
|
||||
) {
|
||||
const state = await prepareOAuthState(options);
|
||||
if (!state) return;
|
||||
const url = new URL(auth_url);
|
||||
url.searchParams.set('client_id', client_id);
|
||||
@@ -258,16 +277,19 @@ export async function onOIDCClicked(auth_url, client_id, openInNewTab = false) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function onGitHubOAuthClicked(github_client_id) {
|
||||
const state = await getOAuthState();
|
||||
export async function onGitHubOAuthClicked(github_client_id, options = {}) {
|
||||
const state = await prepareOAuthState(options);
|
||||
if (!state) return;
|
||||
window.open(
|
||||
`https://github.com/login/oauth/authorize?client_id=${github_client_id}&state=${state}&scope=user:email`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function onLinuxDOOAuthClicked(linuxdo_client_id) {
|
||||
const state = await getOAuthState();
|
||||
export async function onLinuxDOOAuthClicked(
|
||||
linuxdo_client_id,
|
||||
options = { shouldLogout: false },
|
||||
) {
|
||||
const state = await prepareOAuthState(options);
|
||||
if (!state) return;
|
||||
window.open(
|
||||
`https://connect.linux.do/oauth2/authorize?response_type=code&client_id=${linuxdo_client_id}&state=${state}`,
|
||||
|
||||
Reference in New Issue
Block a user