Last active
October 16, 2024 18:35
-
-
Save kentcdodds/c3c0ac4320db453414df9280741f1d98 to your computer and use it in GitHub Desktop.
check local access to mocking workshop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 }, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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