01.software 문서

Community SDK

브라우저용 게시물 읽기와 nullable 상세 결과 참조.

완결된 작업은 Community 가이드에서 시작하세요. 이 페이지는 공개 Community SDK를 설명합니다. import와 peer는 SDK 기본을 참고하세요.

커뮤니티 공개 읽기

커뮤니티 목록과 상세 페이지에는 브라우저에서 써도 안전한 다음 도우미를 사용하세요.

import { createClient } from '@01.software/sdk'

type Client = ReturnType<typeof createClient>

export async function readFirstPost(client: Client) {
  const page = await client.community.listPosts({ limit: 20 })
  if (page.docs.length === 0) return { kind: 'empty' as const }
  const post = await client.community.getPost({ postId: page.docs[0].id })
  if (!post) return { kind: 'absent' as const }
  return { kind: 'found' as const, post }
}

이 조회에는 Publishable Key만 있으면 됩니다. getPost()는 공개 CommunityPost 필드를 반환하고, 없거나 숨겨졌거나 다른 워크스페이스의 글이면 null을 반환합니다. 요청에 고객 JWT를 함께 보낼 수 있지만 Secret Key는 필요하지 않습니다. 원시 client.collections.from('posts')는 서버 전용입니다.

인증된 참여

listPosts({ limit })는 페이지 단위 피드를 반환합니다. getPost({ postId })는 글 하나를 반환하며, 없거나 숨겨졌거나 다른 워크스페이스의 글일 때만 null을 반환하고 그 밖의 오류는 그대로 전달합니다. 고객이 거부된 작업을 Secret Key로 우회하지 마세요. 호스티드 로그인, createComment({ postId, body }), 따로 하는 listComments 조회, 오류 처리는 Community 가이드에서 다룹니다.

다음 액션

목차