Home App Docs Github

Create Private Pages that are accessible only after authorization

Hi there

Is it possible for me to create a Page that can only be viewed privately? I have certain pages on my site that should only be accessible after login

I can control that flow on my application - but nothing stops someone from using my public builder api key from my deployed source code to bypass my frontend (which serves as a proxy to Builder)

1 Like

Howdy @yashu, welcome to the forum!

You can do this using a recently added model setting called public readable. You can go over to builder.io/models and choose your model and hit show more options under model settings and then find the public readable option and turn that off and save your model, e.g. perhaps make a new private-page model of page type with this setting switched off

Note that this model option is currently only live on beta.builder.io but will be in the production builder.io settings UI soon.

Then, go over to your organization settings at builder.io/account/organization and add create a new private key

private key .

Then you can use our content API to request private content using your private key, e.g.

let apiUrl = 'https://cdn.builder.io/api/v2/content'
let modelName = 'private-page'
let content = await request(`${apiUrl}/${modelName}?apiKey=${yourPublicKey}&limit=1&userAttributes.urlPath=/some-page`, {
  headers: { Authorization: `Bearer ${yourPrivateKey}` },
})

Then you can pass that json to render as needed, e.g. with React

let page = content.results[0];

if (page) {
  return <BuilderComponent model="private-page" content={page} />
}

Hope this helps and let me know if I can further explain anything here!