
I am developing an SSR app using SvelteKit, in my app the user can create their account, or simply log in if they are already registered.
In both cases I follow the same implementation demonstrated in the SSR authentication tutorials provided in the documentation.
As in the example below 👇
import { SESSION_COOKIE, createAdminClient } from "$lib/server/appwrite.js"
import { redirect } from "@sveltejs/kit"
export const actions = {
login: async ({ request, cookies }) => {
const form = await request.formData()
const email = form.get("email") as string
const password = form.get("pass") as string
const { account } = createAdminClient()
const session = await account.createEmailPasswordSession(email, password)
cookies.set(SESSION_COOKIE, session.secret, {
sameSite: "strict",
expires: new Date(session.expire),
secure: true,
path: "/",
})
redirect(301, "/admin/meu-negocio")
},
}
The cookie that is stored during the login or account creation process is used to create a session client.
export function createSessionClient(cookies: Cookies) {
const session = cookies.get(SESSION_COOKIE)
if (!session) {
throw new Error("Não existe uma sessão válida")
}
const client = new Client()
.setEndpoint(variables.APPWRITE_ENDPOINT)
.setProject(variables.APPWRITE_PROJECT)
.setSession(session)
return {
get account() {
return new Account(client)
},
get databases() {
return new Databases(client)
},
}
}
After the first access everything works perfectly, in the middleware after instantiating the client I can access the logged in user, through the session client, but when I spend some time without using the app and return it is as if the session is no longer valid and I get the following error 👇
{
code: 401,
type: 'general_unauthorized_scope',
response: {
message: 'User (role: guests) missing scope (account)',
code: 401,
type: 'general_unauthorized_scope',
version: '1.5.7'
}
}
I've looked everywhere for a solution to this, or at least to understand what's happening, and I can't find it.
When I check my console, the user still has the session registered in the app and the sessions were configured to last 1 year. Which in this case already comes by default in Appwrite.
Could anyone help me with this?
Recommended threads
- 404 errors after 7 Days
Local hosted Appwrite via docker. Last version and current version. After exactly 7 days Appwrite stops working. I get 404 route not found, cannot access anyth...
- unable to modify attribute
please help: when I try to modify attribute size or key or anything, I am getting this errors: ``` Deprecated: strtolower(): Passing null to parameter #1 ($str...
- Error 1.7.4 console team no found
In console when i go to auth, select user, select a membership the url not work. Only work searching the team. It is by the region. project-default- and i get ...
