import { PropsWithChildren } from 'react'
import Taro, { useLaunch } from '@tarojs/taro'
import { ensureLogin } from '@/store/session.store'
import './app.scss'

function App({ children }: PropsWithChildren) {
  useLaunch(() => {
    const env = process.env.TARO_APP_CLOUD_ENV

    if (process.env.TARO_ENV === 'weapp' && env && Taro.cloud) {
      Taro.cloud.init({
        env,
        traceUser: true
      })
    }

    // Warm the shared session at launch so the first page already has the user
    // and doesn't need to wait on its own login roundtrip.
    ensureLogin()
  })

  return children
}

export default App

