support at.syu.is oauth
This commit is contained in:
@@ -65,8 +65,17 @@ async function initOAuthClient(): Promise<BrowserOAuthClient> {
|
||||
return oauthClient
|
||||
}
|
||||
|
||||
// Primary OAuth domain
|
||||
const OAUTH_ORIGIN = 'https://syui.ai'
|
||||
|
||||
// Login with handle
|
||||
export async function login(handle: string): Promise<void> {
|
||||
// Redirect to primary OAuth domain if on a different domain
|
||||
if (window.location.origin !== OAUTH_ORIGIN) {
|
||||
window.location.href = `${OAUTH_ORIGIN}${window.location.pathname}?login=${encodeURIComponent(handle)}`
|
||||
return
|
||||
}
|
||||
|
||||
await setNetworkConfig(handle)
|
||||
|
||||
try {
|
||||
|
||||
@@ -91,6 +91,16 @@ async function render(route: Route): Promise<void> {
|
||||
await handleCallback()
|
||||
}
|
||||
|
||||
// Auto-login if redirected from another domain with ?login=handle
|
||||
if (oauthEnabled && searchParams.has('login')) {
|
||||
const loginHandle = searchParams.get('login')
|
||||
if (loginHandle) {
|
||||
window.history.replaceState({}, '', window.location.pathname)
|
||||
await login(loginHandle)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Restore session from storage (skip if oauth disabled)
|
||||
if (oauthEnabled) {
|
||||
await restoreSession()
|
||||
|
||||
Reference in New Issue
Block a user