Skip to content

[ Improvement ] Update Launchpad to use Strapi Cliend SDK #71

@PaulBratslavsky

Description

@PaulBratslavsky

Implement Strapi Client SDK in Launchpad.

Replace the fetch implementation in the fetchContentType.ts file and instead use Strapi Client SDK based on the following package.

Should support both pubic and authenticated requests.

Basic Example:

Client Setup

import { strapi } from '@strapi/client';
import { getStrapiURL } from "@/lib/utils";

const BASE_API_URL = getStrapiURL() + "/api";
const sdk = strapi({ baseURL: BASE_API_URL });

// Helper to get authenticated SDK collection
const getAuthenticatedCollection = (collectionName: string, jwt: string) => {
  const authenticatedSdk = strapi({
    baseURL: BASE_API_URL,
    auth: jwt,
  })
  return authenticatedSdk.collection(collectionName)
}

export { sdk, getAuthenticatedCollection };

Basic usage ( public access )

 const response = await sdk.single('landing-page').find()
  return { data: response.data as TLandingPage }

Basic usage ( auth )

import { getAuthenticatedCollection, sdk } from '@/data/strapi-sdk'

const authenticatedComments = getAuthenticatedCollection('comments', jwt)
  return authenticatedComments.update(commentDocumentId, {
    content: commentData.content,
  }) as Promise<TCommentSingleResponse>

These are just some basic idea examples, but the goal is to have Strapi Client support both pubic and auth request.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions