Skip to content

Commit

Permalink
Merge pull request #98 from privy-open-source/release/0.4.1
Browse files Browse the repository at this point in the history
fix: env undefined in client side
  • Loading branch information
adenvt authored Feb 16, 2024
2 parents 818910e + 7494a12 commit e7661ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
32 changes: 16 additions & 16 deletions src/runtime/nuapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,13 @@ export default defineNuxtPlugin(() => {
const browserId = ref()
const route = useRoute()

const appName = useState(() => env.APP_NAME)
const appVersion = useState(() => env.APP_VERSION || env.BUILD_VERSION)
const platformName = useState(() => env.APP_PLATFORM_NAME || env.PLATFORM_NAME)
const platformType = useState(() => env.APP_PLATFORM_TYPE || env.PLATFORM_TYPE)
const appName = useState('appName', () => env.APP_NAME)
const appVersion = useState('appVersion', () => env.APP_VERSION || env.BUILD_VERSION)
const platformName = useState('platformName', () => env.APP_PLATFORM_NAME || env.PLATFORM_NAME)
const platformType = useState('platformType', () => env.APP_PLATFORM_TYPE || env.PLATFORM_TYPE)

onRequest(async (config) => {
if (config.headers) {
/**
* Add Request ID
*/
if (!config.headers['X-Request-Id'])
config.headers['X-Request-Id'] = uuidv4()

/**
* Add Request timestamp
*/
if (!config.headers['X-Request-Timestamp'])
config.headers['X-Request-Timestamp'] = Date.now().toString()

/**
* Add Browser's fingerprint
*/
Expand Down Expand Up @@ -105,6 +93,18 @@ export default defineNuxtPlugin(() => {
*/
if (route.query.testing === 'true')
config.headers['X-Testing-Mode'] = true

/**
* Add Request ID
*/
if (!config.headers['X-Request-Id'])
config.headers['X-Request-Id'] = uuidv4()

/**
* Add Request timestamp
*/
if (!config.headers['X-Request-Timestamp'])
config.headers['X-Request-Timestamp'] = Date.now().toString()
}

return config
Expand Down
6 changes: 4 additions & 2 deletions types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
interface ImportMetaEnv {
readonly APP_NAME: string,
readonly APP_VERSION: string,
readonly APP_PLATFORM: string,
readonly APP_PLATFORM_NAME: string,
readonly APP_PLATFORM_TYPE: string,

readonly BUILD_VERSION: string,
readonly BUILD_DATE: string,
Expand All @@ -20,7 +21,8 @@ declare global {
interface ProcessEnv {
readonly APP_NAME: string,
readonly APP_VERSION: string,
readonly APP_PLATFORM: string,
readonly APP_PLATFORM_NAME: string,
readonly APP_PLATFORM_TYPE: string,

readonly BUILD_VERSION: string,
readonly BUILD_DATE: string,
Expand Down

0 comments on commit e7661ab

Please sign in to comment.