@ph-cms/client-sdk 0.1.28 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -221,12 +221,16 @@ import { PHCMSClient } from '@ph-cms/client-sdk/core';
221
221
 
222
222
  // Next.js Server Component 또는 API Route 예시
223
223
  export async function getServerSideProps({ req }) {
224
- const { access_token, refresh_token } = req.cookies;
224
+ // .env 등에 설정된 프리픽스를 가져옵니다 (기본값 phcms_)
225
+ const prefix = process.env.NEXT_PUBLIC_PH_CMS_AUTH_STORAGE_PREFIX || "phcms_";
226
+
227
+ const accessToken = req.cookies[`${prefix}access_token`];
228
+ const refreshToken = req.cookies[`${prefix}refresh_token`];
225
229
 
226
230
  const client = new PHCMSClient({
227
231
  baseURL: process.env.API_URL,
228
- accessToken: access_token, // 쿠키에서 뽑은 토큰 주입
229
- refreshToken: refresh_token,
232
+ accessToken, // 쿠키에서 뽑은 토큰 주입
233
+ refreshToken,
230
234
  });
231
235
 
232
236
  // 이제 이 호출은 인증된 상태(Bearer 헤더 포함)로 서버에서 실행됩니다.
@@ -753,6 +757,29 @@ function MyComponent() {
753
757
  }
754
758
  ```
755
759
 
760
+ ### Public Profile (`useUserProfile`)
761
+
762
+ 다른 사용자의 공개 프로필(이름, 아바타, 자기소개 등)을 조회할 때 사용하는 훅입니다.
763
+
764
+ ```tsx
765
+ import { useUserProfile } from '@ph-cms/client-sdk';
766
+
767
+ function UserProfileCard({ userId }) {
768
+ const { data: profile, isLoading, error } = useUserProfile(userId);
769
+
770
+ if (isLoading) return <div>Loading...</div>;
771
+ if (error) return <div>User not found</div>;
772
+
773
+ return (
774
+ <div>
775
+ <img src={profile.avatar_url} alt={profile.display_name} />
776
+ <h3>{profile.display_name} (@{profile.username})</h3>
777
+ <p>{profile.profile_data?.bio}</p>
778
+ </div>
779
+ );
780
+ }
781
+ ```
782
+
756
783
  ### Profile Update (`useUpdateProfile`)
757
784
 
758
785
  사용자가 자신의 프로필을 수정할 수 있는 훅입니다. 업데이트가 성공하면 내부적으로 `refreshUser()`가 호출되어 컨텍스트와 UI가 즉각적으로 갱신됩니다.
@@ -1467,6 +1494,7 @@ const result = await content.list({ channelUid: 'my-channel' });
1467
1494
 
1468
1495
  | 메서드 | 설명 |
1469
1496
  |---|---|
1497
+ | `getProfile(uid: string)` | 유저의 공개 프로필 정보 조회 → `UserProfileDto` |
1470
1498
  | `updateProfile(uid: string, data: UpdateUserProfileRequest)` | 유저의 프로필 정보 업데이트 (일반 유저는 `UpdateUserProfileRequest` 필드만 허용) → `UserDto` |
1471
1499
 
1472
1500
  ### `AuthModule` (`client.auth`)
package/dist/client.js CHANGED
@@ -52,6 +52,7 @@ class PHCMSClient {
52
52
  this.axiosInstance = config.axiosInstance || axios_1.default.create({
53
53
  baseURL: config.baseURL,
54
54
  timeout: config.timeout || 10000,
55
+ withCredentials: true,
55
56
  headers: {
56
57
  'Content-Type': 'application/json',
57
58
  },
@@ -43,6 +43,16 @@ export declare const useUser: () => {
43
43
  isAuthenticated: boolean;
44
44
  error: boolean;
45
45
  };
46
+ /**
47
+ * Hook to fetch a user's public profile.
48
+ */
49
+ export declare const useUserProfile: (uid: string) => import("@tanstack/react-query").UseQueryResult<{
50
+ uid: string;
51
+ username: string | null;
52
+ display_name: string;
53
+ avatar_url: string | null;
54
+ profile_data: Record<string, any>;
55
+ }, Error>;
46
56
  /**
47
57
  * Hook to update a user's profile.
48
58
  * Typically used by a user to update their own profile.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAgreeTerms = exports.useChannelTerms = exports.useUpdateProfile = exports.useUser = exports.termsKeys = void 0;
3
+ exports.useAgreeTerms = exports.useChannelTerms = exports.useUpdateProfile = exports.useUserProfile = exports.useUser = exports.termsKeys = void 0;
4
4
  const react_query_1 = require("@tanstack/react-query");
5
5
  const context_1 = require("../context");
6
6
  exports.termsKeys = {
@@ -15,6 +15,18 @@ const useUser = () => {
15
15
  return { data: user, isLoading, isAuthenticated, error: isError };
16
16
  };
17
17
  exports.useUser = useUser;
18
+ /**
19
+ * Hook to fetch a user's public profile.
20
+ */
21
+ const useUserProfile = (uid) => {
22
+ const client = (0, context_1.usePHCMS)();
23
+ return (0, react_query_1.useQuery)({
24
+ queryKey: ['user-profile', uid],
25
+ queryFn: () => client.user.getProfile(uid),
26
+ enabled: !!uid,
27
+ });
28
+ };
29
+ exports.useUserProfile = useUserProfile;
18
30
  /**
19
31
  * Hook to update a user's profile.
20
32
  * Typically used by a user to update their own profile.
@@ -1,9 +1,15 @@
1
- import { UpdateUserProfileRequest, UserDto } from "@ph-cms/api-contract";
1
+ import { UpdateUserProfileRequest, UserDto, UserProfileDto } from "@ph-cms/api-contract";
2
2
  import { AxiosInstance } from "axios";
3
3
  export declare class UserModule {
4
4
  private client;
5
5
  private prefix;
6
6
  constructor(client: AxiosInstance, prefix?: string);
7
+ /**
8
+ * Retrieves a user's public profile.
9
+ *
10
+ * @param uid - The UID of the user.
11
+ */
12
+ getProfile(uid: string): Promise<UserProfileDto>;
7
13
  /**
8
14
  * Updates a user's profile.
9
15
  *
@@ -6,6 +6,14 @@ class UserModule {
6
6
  this.client = client;
7
7
  this.prefix = prefix;
8
8
  }
9
+ /**
10
+ * Retrieves a user's public profile.
11
+ *
12
+ * @param uid - The UID of the user.
13
+ */
14
+ async getProfile(uid) {
15
+ return this.client.get(`${this.prefix}/users/${uid}/profile`);
16
+ }
9
17
  /**
10
18
  * Updates a user's profile.
11
19
  *
package/dist/types.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { AuthStatus, PHCMSContextType, PHCMSProviderProps } from './context
5
5
  export type { FirebaseAuthSyncProps, UseFirebaseAuthSyncOptions, UseFirebaseAuthSyncReturn } from './hooks/useFirebaseAuthSync';
6
6
  export type { StampAvailability, CheckStampAvailabilityParams } from './hooks/useStampTour';
7
7
  export type { AuthResponse, FirebaseExchangeRequest, LoginRequest, RefreshTokenRequest, RegisterRequest } from '@ph-cms/api-contract';
8
- export type { UserDto } from '@ph-cms/api-contract';
8
+ export type { UserDto, UserProfileDto } from '@ph-cms/api-contract';
9
9
  export type { ChannelDto, CheckHierarchyQuery } from '@ph-cms/api-contract';
10
10
  export type { ContentDto, ContentStatDto, ContentMediaDto, CreateContentRequest, ListContentQuery, PagedContentListResponse, UpdateContentRequest } from '@ph-cms/api-contract';
11
11
  export type { HierarchySetDto } from '@ph-cms/api-contract';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ph-cms/client-sdk",
3
- "version": "0.1.28",
3
+ "version": "0.1.31",
4
4
  "description": "Unified PH-CMS Client SDK (React + Core)",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "LICENSE"
31
31
  ],
32
32
  "dependencies": {
33
- "@ph-cms/api-contract": "^0.1.10",
33
+ "@ph-cms/api-contract": "^0.1.11",
34
34
  "@tanstack/react-query": "^5.0.0",
35
35
  "axios": "^1.6.0",
36
36
  "zod": "^3.22.4"