fix oauth config
This commit is contained in:
2
.github/workflows/deploy.yml
vendored
2
.github/workflows/deploy.yml
vendored
@@ -2,7 +2,7 @@ name: Deploy to GitHub Pages
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [min]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
13
index.html
13
index.html
@@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>syui.ai</title>
|
|
||||||
<link rel="stylesheet" href="/src/styles/main.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script type="module" src="/src/main.ts"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"title": "syui.ai",
|
"title": "syui.ai",
|
||||||
"handle": "syui.syui.ai",
|
"handle": "syui.syui.ai",
|
||||||
"collection": "ai.syui.log.post",
|
"collection": "ai.syui.log.post",
|
||||||
"network": "syu.is",
|
"network": "syu.is",
|
||||||
"color": "#EF454A",
|
"color": "#EF454A",
|
||||||
"siteUrl": "https://syui.ai"
|
"siteUrl": "https://syui.ai",
|
||||||
|
"oauth": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { isLoggedIn, getLoggedInHandle } from '../lib/auth'
|
import { isLoggedIn, getLoggedInHandle } from '../lib/auth'
|
||||||
|
|
||||||
export function renderHeader(currentHandle: string): string {
|
export function renderHeader(currentHandle: string, oauth: boolean = true): string {
|
||||||
const loggedIn = isLoggedIn()
|
const loggedIn = isLoggedIn()
|
||||||
const handle = getLoggedInHandle()
|
const handle = getLoggedInHandle()
|
||||||
|
|
||||||
const loginBtn = loggedIn
|
let loginBtn = ''
|
||||||
? `<button type="button" class="header-btn user-btn" id="logout-btn" title="Logout">${handle || 'logout'}</button>`
|
if (oauth) {
|
||||||
: `<button type="button" class="header-btn login-btn" id="login-btn" title="Login"><img src="/icon/user.svg" alt="Login" class="login-icon"></button>`
|
loginBtn = loggedIn
|
||||||
|
? `<button type="button" class="header-btn user-btn" id="logout-btn" title="Logout">${handle || 'logout'}</button>`
|
||||||
|
: `<button type="button" class="header-btn login-btn" id="login-btn" title="Login"><img src="/icon/user.svg" alt="Login" class="login-icon"></button>`
|
||||||
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<header id="header">
|
<header id="header">
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ async function render(route: Route): Promise<void> {
|
|||||||
document.title = config.title
|
document.title = config.title
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check OAuth enabled
|
||||||
|
const oauthEnabled = config.oauth !== false
|
||||||
|
|
||||||
// Handle OAuth callback if present (check both ? and #)
|
// Handle OAuth callback if present (check both ? and #)
|
||||||
const searchParams = new URLSearchParams(window.location.search)
|
const searchParams = new URLSearchParams(window.location.search)
|
||||||
const hashParams = window.location.hash ? new URLSearchParams(window.location.hash.slice(1)) : null
|
const hashParams = window.location.hash ? new URLSearchParams(window.location.hash.slice(1)) : null
|
||||||
@@ -108,7 +111,7 @@ async function render(route: Route): Promise<void> {
|
|||||||
|
|
||||||
if (!did) {
|
if (!did) {
|
||||||
app.innerHTML = `
|
app.innerHTML = `
|
||||||
${renderHeader(handle)}
|
${renderHeader(handle, oauthEnabled)}
|
||||||
<div class="error">Could not resolve handle: ${handle}</div>
|
<div class="error">Could not resolve handle: ${handle}</div>
|
||||||
${renderFooter(handle)}
|
${renderFooter(handle)}
|
||||||
`
|
`
|
||||||
@@ -139,7 +142,7 @@ async function render(route: Route): Promise<void> {
|
|||||||
const langList = Array.from(availableLangs)
|
const langList = Array.from(availableLangs)
|
||||||
|
|
||||||
// Build page
|
// Build page
|
||||||
let html = renderHeader(handle)
|
let html = renderHeader(handle, oauthEnabled)
|
||||||
|
|
||||||
// Mode tabs (Blog/Browser/Post/PDS)
|
// Mode tabs (Blog/Browser/Post/PDS)
|
||||||
const activeTab = route.type === 'postpage' ? 'post' :
|
const activeTab = route.type === 'postpage' ? 'post' :
|
||||||
@@ -264,7 +267,7 @@ async function render(route: Route): Promise<void> {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Render error:', error)
|
console.error('Render error:', error)
|
||||||
app.innerHTML = `
|
app.innerHTML = `
|
||||||
${renderHeader(currentHandle)}
|
${renderHeader(currentHandle, false)}
|
||||||
<div class="error">Error: ${error}</div>
|
<div class="error">Error: ${error}</div>
|
||||||
${renderFooter(currentHandle)}
|
${renderFooter(currentHandle)}
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export interface AppConfig {
|
|||||||
network: string
|
network: string
|
||||||
color: string
|
color: string
|
||||||
siteUrl: string
|
siteUrl: string
|
||||||
|
oauth?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Networks {
|
export interface Networks {
|
||||||
|
|||||||
Reference in New Issue
Block a user