#[SOLVED] Next.js Login Self-hosted (role: applications) missing scope (public) Error

18 messages · Page 1 of 1 (latest)

random comet
#

Im trying to follow the tutorial from: https://www.youtube.com/watch?v=l9zh0pqEHyc
but when I created the API Key it has all the permissions. When Im trying to createSession it says:
(role: applications) missing scope (public)

can someone guide me? 🙏 thanks!

In this 4-hour project-based course, we will build a booking app for meeting/conference rooms. We will be using React/Next along wth Appwrite, which is an open-source, all-in-one platform with databases, authentication, storage and more.

Visit Appwrite and claim $50 in free Appwrite Cloud Pro credits:
https://apwr.dev/traversymedia50

Final Cod...

▶ Play video
whole veldt
#

Please post a snippit of the code you're using that is throwing the error.

random comet
#
const createAdminClient = async () => {
  const client = new Client()
    .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_URL)
    .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID)
    .setKey(process.env.NEXT_PRIVATE_APPWRITE_KEY)

  return {
    get account() {
      return new Account(client)
    },
    get databases() {
      return new Databases(client)
    },
    get storage() {
      return new Storage(client)
    },
  }
}```
#

here you can see that its getgging the AdminClient.

#
'use server'

import { createAdminClient } from '@/lib/appwrite'
import { signinSchema } from '@/schemas'
import { cookies } from 'next/headers'

export async function createSession(
  previousState: any,
  formData: any
): Promise<{ success: boolean; error?: string | Record<string, string[]> }> {
  const validatedFields = signinSchema.safeParse(formData)

  if (!validatedFields.success) {
    return {
      success: false,
      error: validatedFields.error.flatten().fieldErrors,
    }
  }

  // Get account instance
  const { account } = await createAdminClient()

  try {
    console.log('Creating session...', {
      email: validatedFields.data.email,
      password: validatedFields.data.password,
    })
    const session = await account.createEmailPasswordSession(validatedFields.data.email, validatedFields.data.password)

    // Create cookie
    cookies().set('next-appwrite-session', session.secret, {
      httpOnly: true,
      secure: true,
      sameSite: 'strict',
      expires: new Date(session.expire),
      path: '/',
    })

    return {
      success: true,
      error: null,
    }
  } catch (error) {
    console.log('🛑 createSession: ', error.message)
    return {
      success: false,
      error: error.message,
    }
  }
}
#

and the problem is when the account its being instantiated and creating the email password session :/

whole veldt
#

Are you sure the API key is actually set? What does your .env look like?

random comet
#

yeah, and its printing when I call it

#

I will later remote that API Key but you can see that its there

whole veldt
#

Does the account already exist when you are trying to create the session?

random comet
#

yes

whole veldt
#

are you importing node-appwrite?

random comet
#

yes, Im noticing that the cloud Appwrite contains this permission:
sessions.write
but the self-hosted doesn't

is there any reason?

whole veldt
#

What version are you on?

random comet
#

appwrite/appwrite:1.4.13

whole veldt
#

you need 1.5.x, so that's most likely your issue.

#

SSR was added in 1.5.x, so you're missing functionality that allows for this

random comet
#

let me check on this ! thanks @whole veldt 🙏