Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Last active October 16, 2024 18:35
Show Gist options
  • Save kentcdodds/c3c0ac4320db453414df9280741f1d98 to your computer and use it in GitHub Desktop.
Save kentcdodds/c3c0ac4320db453414df9280741f1d98 to your computer and use it in GitHub Desktop.
check local access to mocking workshop
#!/usr/bin/env node
import { promises as fs } from 'fs'
import { homedir } from 'os'
import path from 'path'
const homeDir = homedir()
const dataFilePath = path.join(homeDir, '.epicshop', 'data.json')
let data
try {
const rawData = await fs.readFile(dataFilePath, 'utf8')
data = JSON.parse(rawData)
} catch (error) {
console.error('Error reading or parsing data.json:', error)
}
const accessToken = data.authInfo?.tokenSet?.access_token
if (!accessToken) {
throw new Error('No access token found')
}
const infoResponse = await fetch(
'https://www.epicweb.dev/api/workshops/mocking-techniques-in-vitest/access',
{
headers: {
authorization: `Bearer ${accessToken}`,
},
},
)
console.log(infoResponse)
console.dir(
infoResponse.headers.get('content-type').includes('application/json')
? await infoResponse.json()
: await infoResponse.text(),
{ depth: 10, colors: true },
)
{
"name": "check-local-access-to-mocking-workshop",
"type": "module",
"bin": "index.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment