How config matix with nuxt

Hello guys! I have an app on Nuxt.js. I’m trying to create a chat in my app with Matrix. I installed matrix-js-sdk and can’t completely configure it. I create a matrix-js-sdk folder with an index.js file in ~plugins/ directory. And code inside index.js:


import * as sdk from 'matrix-js-sdk'

const token = localStorage.getItem('token')

const myUserId = 'sanjar'
const myAccessToken = `Bearer ${token}`
const matrixClient = sdk.createClient({
  baseUrl: '[there is my chat serves url]',
  accessToken: myAccessToken,
  userId: myUserId,

matrixClient.on('RoomMember.membership', function (event, member) {
  if (member.membership === 'invite' && member.userId === myUserId) {
    matrixClient.joinRoom(member.roomId).then(function () {
      console.log('Auto-joined %s', member.roomId)


and when I run the app I get an error response code with 401.