Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ SITE_ICP=""
## You are advised to fill in 30 - 90
COUNT_DAYS=60

# Show Links
# Show Link
## Whether to show sites links
SHOW_LINKS=true
SHOW_LINK=true

# Password
## If you want to protect the data, you can set a password
SITE_PASSWORD=""
## Key used for jwt verification, required
SITE_SECRE_KEY="site-status"
SITE_SECRE_KEY="site-status"
2 changes: 1 addition & 1 deletion app/components/SiteNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const navMenu = computed<DropdownOption[]>(() => [
{
key: "logout",
label: t("nav.logout"),
show: statusStore.loginStatus,
show: statusStore.loginStatus && config.public.hasPassword,
icon: renderIcon("icon:logout"),
props: {
onClick: () => {
Expand Down
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const siteConfig = {
siteLogo: process.env.SITE_LOGO || "/favicon.ico",
siteIcp: process.env.SITE_ICP || "",
countDays: Number(process.env.COUNT_DAYS || 60),
showLink: process.env.SHOW_LINK === "true" || true,
showLink: process.env.SHOW_LINK === "true",
platform: process.env.DEPLOYMENT_PLATFORM || "cloudflare",
version: pkg.version,
hasPassword: !!process.env.SITE_PASSWORD,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

当前 !!process.env.SITE_PASSWORD 的逻辑在 SITE_PASSWORD 环境变量仅包含空格(例如 " ")时,hasPassword 会被设为 true。这可能不是预期的行为,因为一个只包含空格的密码通常被认为是无效的。建议在检查之前先对字符串进行 trim() 操作,以处理这种边缘情况,增强代码的健壮性。

Suggested change
hasPassword: !!process.env.SITE_PASSWORD,
hasPassword: !!process.env.SITE_PASSWORD?.trim(),

};

export default defineNuxtConfig({
Expand Down