Skip to content

Commit

Permalink
fix login check
Browse files Browse the repository at this point in the history
  • Loading branch information
gusibi committed Oct 12, 2024
1 parent a0e7786 commit 8b562f2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
15 changes: 3 additions & 12 deletions components/CommentBox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="mb-4 rounded-lg border border-gray-200 dark:border-gray-700 ">
<div v-if="isLoggedIn.value" class="p-3">
<div v-if="isLoggedIn" class="p-3">
<div class="flex items-start space-x-3">
<img :src="user.user_metadata.avatar_url" :alt="user.user_metadata.full_name" class="w-8 h-8 rounded-full">
<div class="flex-grow">
Expand All @@ -27,22 +27,14 @@ const supabase = useSupabaseClient()
const route = useRoute()
const commentText = ref('')
const isLoggedIn = ref(false)
const emit = defineEmits(['comment-submitted'])
// 新增:检查登录状态的函数
const checkLoginStatus = () => {
const isLoggedIn = computed(() => {
const githubToken = useCookie('github_token').value
const githubUser = useCookie('github_username').value
isLoggedIn.value = !!githubToken && !!githubUser
}
// console.log("user: ", user, "is_login", isLoggedIn.value, "<<<")
// 在组件挂载时检查登录状态
onMounted(() => {
checkLoginStatus()
return !!githubToken && !!githubUser && !!user.value
})
Expand All @@ -56,7 +48,6 @@ const submitComment = async () => {
commentText: commentText.value
}
})
console.log(response)
emit('comment-submitted', response) // 发出包含新评论数据的事件
commentText.value = '' // 清空输入框
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions components/RepoTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const formatDate = (dateString: string, showYear = false) => {
}
const truncatedBody = (post: string) => {
if (!post) {
return ""
}
const maxLength = 400;
if (post.length <= maxLength) {
return post;
Expand Down
23 changes: 19 additions & 4 deletions pages/blog/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="mb-4 flex justify-center items-center text-sm text-gray-600 dark:text-gray-400">
<PostLabels :labels="post.labels" />
</div>
<div class="prose dark:prose-invert max-w-none" v-html="$md(post.body)" />
<div class="prose dark:prose-invert max-w-none" v-html="$md(post.body || '')" />
<!-- 底部信息栏 -->
<div class=" pt-3 flex justify-between items-center text-sm">
<!-- 左下角 GitHub 链接 -->
Expand Down Expand Up @@ -57,16 +57,16 @@ const post = ref(postData.value)
useHead(() => ({
title: post.value?.title,
meta: [
{ name: 'description', content: post.value?.body.substring(0, 160) + '...' },
{ name: 'description', content: truncatedBody(post.value?.body, 160) },
{ name: 'keywords', content: post.value?.labels.map(label => label.name).join(', ') },
// Open Graph
{ property: 'og:title', content: post.value?.title },
{ property: 'og:description', content: post.value?.body.substring(0, 160) + '...' },
{ property: 'og:description', content: truncatedBody(post.value?.body, 160) },
{ property: 'og:type', content: 'article' },
{ property: 'og:url', content: `https://momo.gusibi.mobi/blog/${route.params.id}` },
// Twitter Card
{ name: 'twitter:title', content: post.value?.title },
{ name: 'twitter:description', content: post.value?.body.substring(0, 160) + '...' },
{ name: 'twitter:description', content: truncatedBody(post.value?.body, 160) },
],
link: [
{ rel: 'canonical', href: `https://momo.gusibi.mobi/blog/${route.params.id}` }
Expand All @@ -85,6 +85,21 @@ const formatDate = (dateString: string, showYear = false) => {
return new Intl.DateTimeFormat('en-US', options).format(date)
}
const truncatedBody = (post: string, length: number) => {
if (!post) {
return ""
}
let maxLength = 400;
if (length > 0) {
maxLength = length
}
if (post.length <= maxLength) {
return post;
}
return post.slice(0, maxLength).trim() + '...';
}
const getCommentCount = (comments: Array<{
id: number
user: { login: string }
Expand Down
6 changes: 6 additions & 0 deletions pages/logout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const handleLogout = async () => {
try {
const { error } = await supabase.auth.signOut()
if (error) throw error
// 删除 GitHub 相关的 cookie
const githubTokenCookie = useCookie('github_token')
const githubUsernameCookie = useCookie('github_username')
githubTokenCookie.value = null
githubUsernameCookie.value = null
// 登出成功后重定向到首页或登录页
await router.push('/')
Expand Down
24 changes: 20 additions & 4 deletions pages/repo/[repo_owner]/[repo_name]/blog/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="mb-4 flex justify-center items-center text-sm text-gray-600 dark:text-gray-400">
<PostLabels :labels="post.labels" :repo-url="post.repo_url" />
</div>
<div class="prose dark:prose-invert max-w-none" v-html="$md(post.body)" />
<div class="prose dark:prose-invert max-w-none" v-html="$md(post.body || '')" />
<!-- 底部信息栏 -->
<div class=" pt-3 flex justify-between items-center text-sm">
<!-- 左下角 GitHub 链接 -->
Expand Down Expand Up @@ -54,29 +54,45 @@ const { data: postData } = await useAsyncData('post', () =>
)
const post = ref(postData.value)
const truncatedBody = (post: string, length: number) => {
if (!post) {
return ""
}
let maxLength = 400;
if (length > 0) {
maxLength = length
}
if (post.length <= maxLength) {
return post;
}
return post.slice(0, maxLength).trim() + '...';
}
// console.log("post", post.value)
// console.log("reactions", post.value.reactions)
// console.log("comment: ", post.value.comments)
// SEO优化
useHead(() => ({
title: post.value?.title,
meta: [
{ name: 'description', content: post.value?.body.substring(0, 160) + '...' },
{ name: 'description', content: truncatedBody(post.value?.body, 160) },
{ name: 'keywords', content: post.value?.labels.map(label => label.name).join(', ') },
// Open Graph
{ property: 'og:title', content: post.value?.title },
{ property: 'og:description', content: post.value?.body.substring(0, 160) + '...' },
{ property: 'og:description', content: truncatedBody(post.value?.body, 160) },
{ property: 'og:type', content: 'article' },
{ property: 'og:url', content: `https://momo.gusibi.mobi/blog/${route.params.id}` },
// Twitter Card
{ name: 'twitter:title', content: post.value?.title },
{ name: 'twitter:description', content: post.value?.body.substring(0, 160) + '...' },
{ name: 'twitter:description', content: truncatedBody(post.value?.body, 160) },
],
link: [
{ rel: 'canonical', href: `https://momo.gusibi.mobi/blog/${route.params.id}` }
],
}))
const formatDate = (dateString: string, showYear = false) => {
const date = new Date(dateString)
const options: Intl.DateTimeFormatOptions = {
Expand Down
2 changes: 1 addition & 1 deletion server/api/repo/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineEventHandler(async (event) => {
repos = defaultRepos
}

console.log("repos: ", repos)
// console.log("repos: ", repos)
const startIndex = (page - 1) * limit
const endIndex = page * limit

Expand Down

0 comments on commit 8b562f2

Please sign in to comment.