Home > front end >  'The library has not yet been initialized' when I use @microsoft/teams-js in nuxtjs
'The library has not yet been initialized' when I use @microsoft/teams-js in nuxtjs

Time:05-08

this happened when I tried to use @microsoft/teams-js for Single Sign-on (SSO) purposes in nuxtjs.

<template>
  <Tutorial />
</template>

<script>
export default {
  name: 'IndexPage',
  async mounted () {
    const microsoftTeams = await import('@microsoft/teams-js')
    // console.log('client => ', microsoftTeams)
    microsoftTeams.authentication.getAuthToken({
      successCallback: (token) => {
        console.log('token', token)
        microsoftTeams.appInitialization.notifySuccess()
      },
      failureCallback: (message) => {
        // console.log('error', message)
        microsoftTeams.appInitialization.notifyFailure({
          reason: microsoftTeams.appInitialization.FailedReason.AuthFailed,
          message
        })
      },
      resources: ['']
    })
  }
}
</script>

enter image description here

CodePudding user response:

Initialize the library, before calling other methods, as per the documentation:

microsoftTeams.initialize()

This of course only works when running in a Teams app (tab or personal)

  • Related