Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
019ae700
authored
Dec 08, 2025
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Try to fix login error "already logged in" issue
parent
52c9e0ed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
16 deletions
+48
-16
web/src/components/auth/LoginForm.jsx
+9
-4
web/src/components/auth/RegisterForm.jsx
+9
-4
web/src/helpers/api.js
+30
-8
No files found.
web/src/components/auth/LoginForm.jsx
View file @
019ae700
...
@@ -294,7 +294,7 @@ const LoginForm = () => {
...
@@ -294,7 +294,7 @@ const LoginForm = () => {
setGithubButtonDisabled
(
true
);
setGithubButtonDisabled
(
true
);
},
20000
);
},
20000
);
try
{
try
{
onGitHubOAuthClicked
(
status
.
github_client_id
);
onGitHubOAuthClicked
(
status
.
github_client_id
,
{
shouldLogout
:
true
}
);
}
finally
{
}
finally
{
// 由于重定向,这里不会执行到,但为了完整性添加
// 由于重定向,这里不会执行到,但为了完整性添加
setTimeout
(()
=>
setGithubLoading
(
false
),
3000
);
setTimeout
(()
=>
setGithubLoading
(
false
),
3000
);
...
@@ -309,7 +309,7 @@ const LoginForm = () => {
...
@@ -309,7 +309,7 @@ const LoginForm = () => {
}
}
setDiscordLoading
(
true
);
setDiscordLoading
(
true
);
try
{
try
{
onDiscordOAuthClicked
(
status
.
discord_client_id
);
onDiscordOAuthClicked
(
status
.
discord_client_id
,
{
shouldLogout
:
true
}
);
}
finally
{
}
finally
{
// 由于重定向,这里不会执行到,但为了完整性添加
// 由于重定向,这里不会执行到,但为了完整性添加
setTimeout
(()
=>
setDiscordLoading
(
false
),
3000
);
setTimeout
(()
=>
setDiscordLoading
(
false
),
3000
);
...
@@ -324,7 +324,12 @@ const LoginForm = () => {
...
@@ -324,7 +324,12 @@ const LoginForm = () => {
}
}
setOidcLoading
(
true
);
setOidcLoading
(
true
);
try
{
try
{
onOIDCClicked
(
status
.
oidc_authorization_endpoint
,
status
.
oidc_client_id
);
onOIDCClicked
(
status
.
oidc_authorization_endpoint
,
status
.
oidc_client_id
,
false
,
{
shouldLogout
:
true
},
);
}
finally
{
}
finally
{
// 由于重定向,这里不会执行到,但为了完整性添加
// 由于重定向,这里不会执行到,但为了完整性添加
setTimeout
(()
=>
setOidcLoading
(
false
),
3000
);
setTimeout
(()
=>
setOidcLoading
(
false
),
3000
);
...
@@ -339,7 +344,7 @@ const LoginForm = () => {
...
@@ -339,7 +344,7 @@ const LoginForm = () => {
}
}
setLinuxdoLoading
(
true
);
setLinuxdoLoading
(
true
);
try
{
try
{
onLinuxDOOAuthClicked
(
status
.
linuxdo_client_id
);
onLinuxDOOAuthClicked
(
status
.
linuxdo_client_id
,
{
shouldLogout
:
true
}
);
}
finally
{
}
finally
{
// 由于重定向,这里不会执行到,但为了完整性添加
// 由于重定向,这里不会执行到,但为了完整性添加
setTimeout
(()
=>
setLinuxdoLoading
(
false
),
3000
);
setTimeout
(()
=>
setLinuxdoLoading
(
false
),
3000
);
...
...
web/src/components/auth/RegisterForm.jsx
View file @
019ae700
...
@@ -261,7 +261,7 @@ const RegisterForm = () => {
...
@@ -261,7 +261,7 @@ const RegisterForm = () => {
setGithubButtonDisabled
(
true
);
setGithubButtonDisabled
(
true
);
},
20000
);
},
20000
);
try
{
try
{
onGitHubOAuthClicked
(
status
.
github_client_id
);
onGitHubOAuthClicked
(
status
.
github_client_id
,
{
shouldLogout
:
true
}
);
}
finally
{
}
finally
{
setTimeout
(()
=>
setGithubLoading
(
false
),
3000
);
setTimeout
(()
=>
setGithubLoading
(
false
),
3000
);
}
}
...
@@ -270,7 +270,7 @@ const RegisterForm = () => {
...
@@ -270,7 +270,7 @@ const RegisterForm = () => {
const
handleDiscordClick
=
()
=>
{
const
handleDiscordClick
=
()
=>
{
setDiscordLoading
(
true
);
setDiscordLoading
(
true
);
try
{
try
{
onDiscordOAuthClicked
(
status
.
discord_client_id
);
onDiscordOAuthClicked
(
status
.
discord_client_id
,
{
shouldLogout
:
true
}
);
}
finally
{
}
finally
{
setTimeout
(()
=>
setDiscordLoading
(
false
),
3000
);
setTimeout
(()
=>
setDiscordLoading
(
false
),
3000
);
}
}
...
@@ -279,7 +279,12 @@ const RegisterForm = () => {
...
@@ -279,7 +279,12 @@ const RegisterForm = () => {
const
handleOIDCClick
=
()
=>
{
const
handleOIDCClick
=
()
=>
{
setOidcLoading
(
true
);
setOidcLoading
(
true
);
try
{
try
{
onOIDCClicked
(
status
.
oidc_authorization_endpoint
,
status
.
oidc_client_id
);
onOIDCClicked
(
status
.
oidc_authorization_endpoint
,
status
.
oidc_client_id
,
false
,
{
shouldLogout
:
true
},
);
}
finally
{
}
finally
{
setTimeout
(()
=>
setOidcLoading
(
false
),
3000
);
setTimeout
(()
=>
setOidcLoading
(
false
),
3000
);
}
}
...
@@ -288,7 +293,7 @@ const RegisterForm = () => {
...
@@ -288,7 +293,7 @@ const RegisterForm = () => {
const
handleLinuxDOClick
=
()
=>
{
const
handleLinuxDOClick
=
()
=>
{
setLinuxdoLoading
(
true
);
setLinuxdoLoading
(
true
);
try
{
try
{
onLinuxDOOAuthClicked
(
status
.
linuxdo_client_id
);
onLinuxDOOAuthClicked
(
status
.
linuxdo_client_id
,
{
shouldLogout
:
true
}
);
}
finally
{
}
finally
{
setTimeout
(()
=>
setLinuxdoLoading
(
false
),
3000
);
setTimeout
(()
=>
setLinuxdoLoading
(
false
),
3000
);
}
}
...
...
web/src/helpers/api.js
View file @
019ae700
...
@@ -231,8 +231,22 @@ export async function getOAuthState() {
...
@@ -231,8 +231,22 @@ export async function getOAuthState() {
}
}
}
}
export
async
function
onDiscordOAuthClicked
(
client_id
)
{
async
function
prepareOAuthState
(
options
=
{})
{
const
state
=
await
getOAuthState
();
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
;
if
(
!
state
)
return
;
const
redirect_uri
=
`
${
window
.
location
.
origin
}
/oauth/discord`
;
const
redirect_uri
=
`
${
window
.
location
.
origin
}
/oauth/discord`
;
const
response_type
=
'code'
;
const
response_type
=
'code'
;
...
@@ -242,8 +256,13 @@ export async function onDiscordOAuthClicked(client_id) {
...
@@ -242,8 +256,13 @@ export async function onDiscordOAuthClicked(client_id) {
);
);
}
}
export
async
function
onOIDCClicked
(
auth_url
,
client_id
,
openInNewTab
=
false
)
{
export
async
function
onOIDCClicked
(
const
state
=
await
getOAuthState
();
auth_url
,
client_id
,
openInNewTab
=
false
,
options
=
{},
)
{
const
state
=
await
prepareOAuthState
(
options
);
if
(
!
state
)
return
;
if
(
!
state
)
return
;
const
url
=
new
URL
(
auth_url
);
const
url
=
new
URL
(
auth_url
);
url
.
searchParams
.
set
(
'client_id'
,
client_id
);
url
.
searchParams
.
set
(
'client_id'
,
client_id
);
...
@@ -258,16 +277,19 @@ export async function onOIDCClicked(auth_url, client_id, openInNewTab = false) {
...
@@ -258,16 +277,19 @@ export async function onOIDCClicked(auth_url, client_id, openInNewTab = false) {
}
}
}
}
export
async
function
onGitHubOAuthClicked
(
github_client_id
)
{
export
async
function
onGitHubOAuthClicked
(
github_client_id
,
options
=
{}
)
{
const
state
=
await
getOAuthState
(
);
const
state
=
await
prepareOAuthState
(
options
);
if
(
!
state
)
return
;
if
(
!
state
)
return
;
window
.
open
(
window
.
open
(
`https://github.com/login/oauth/authorize?client_id=
${
github_client_id
}
&state=
${
state
}
&scope=user:email`
,
`https://github.com/login/oauth/authorize?client_id=
${
github_client_id
}
&state=
${
state
}
&scope=user:email`
,
);
);
}
}
export
async
function
onLinuxDOOAuthClicked
(
linuxdo_client_id
)
{
export
async
function
onLinuxDOOAuthClicked
(
const
state
=
await
getOAuthState
();
linuxdo_client_id
,
options
=
{
shouldLogout
:
false
},
)
{
const
state
=
await
prepareOAuthState
(
options
);
if
(
!
state
)
return
;
if
(
!
state
)
return
;
window
.
open
(
window
.
open
(
`https://connect.linux.do/oauth2/authorize?response_type=code&client_id=
${
linuxdo_client_id
}
&state=
${
state
}
`
,
`https://connect.linux.do/oauth2/authorize?response_type=code&client_id=
${
linuxdo_client_id
}
&state=
${
state
}
`
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment