Recent searches


No recent searches

secure settings not injecting.



Posted Feb 19, 2024

Hello,

I'm not sure if I'm losing my mind or just don't know how to code. Probably the latter.

I'm trying to use the ```secure:true``` but it doesn't seem to be working.

CODE: 

import React, { useState, useEffect } from 'react'
import zafClient from '../../../zafClient'

const CaseList = () => {
  const [caseData, setCaseData] = useState(null)
  const [isLoading, setIsLoading] = useState(true)

  useEffect(() => {
    const fetchData = async () => {
      try {
        const client = zafClient

        // Retrieve metadata using the client.metadata() method
        //const metadata = await client.metadata();
        //const token = metadata.settings.token; // Assuming the token is stored in the settings
       

        const options = {
          url: 'https://api.example.com/usage',
          headers: { "api-token": `{{settings.token}}` },
          secure: true,
          type: 'GET',
          contentType: 'application/json'
        }

        const response = await client.request(options)

        if (!response) {
          throw new Error('No response from the API')
        }

        setCaseData(response.data) // Ensure you're setting the correct part of the response
      } catch (error) {
        console.error('Error fetching case data:', error)
        // Log more error details if available
        if (error.response) {
          console.error('Error response:', error.response)
        }
      }
      setIsLoading(false)
    }

    fetchData()
  }, [])

  return (
    <div>
      {isLoading ? (
        <p>Loading case data...</p>
      ) : caseData ? (
        <ul>
          {/* Ensure these fields match the structure of your response data */}
          <li><strong>Job Number:</strong> {caseData.JobNum}</li>
          <li><strong>Part Number:</strong> {caseData.PartNum}</li>
          <li><strong>Description:</strong> {caseData.Description}</li>
          {/* Add other fields as needed */}
        </ul>
      ) : (
        <p>No case data available.</p>
      )}
    </div>
  )
}

export default CaseList

I'm just returning 



What have I done wrong?

0

1

1 comment

image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Aaron! Are you looking at this in your browser's network tab? If so, that's the purpose of secure settings...you aren't going to see anything other than the placeholder in the browser. We add that value at the proxy layer to prevent anyone from grabbing this value. Let me know if you're seeing this issue elsewhere and if you are, can you tell me if your app is deployed or are you running this locally?

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post