
Hello, I am trying to implement a middleware to protect the routes in my website. However it is not working as it is throwing a AppwriteException: User (role: guests) missing scope (account) at Generator.next (<anonymous>).

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { Client, Account } from "appwrite";
import { appwriteConfig } from "@/lib/appwrite/config";
export async function middleware(request: NextRequest) {
const client = new Client()
.setProject(appwriteConfig.projectId);
const account = new Account(client);
let isAuthenticated;
isAuthenticated = await account.get();
if (!isAuthenticated && request.nextUrl.pathname === "/home" ) {
console.log(isAuthenticated);
const signInUrl = new URL('/sign-in', request.url);
return NextResponse.redirect(signInUrl);
}
return NextResponse.next();
}

For now I have the code so that the user can't acess the home page if they have not logged in
Recommended threads
- Storage & Database is not allowing.
Storage & Database is not allowing to CRUD after i have logged in ? Using web SDK with next.js without any SSR or node-sdk.
- API Endpoint to Verify Password.
I have 2 use cases where i need to verify a users password outside of login, e.g. Updating user account data (such as name, or prefs, or data in a users databa...
- login backend and frontend
I'm using Remix, as my Backend (node). and react on my frontend. Until now, i did SSR login. saved the secret.. and it's fine. For many simpler requests i wish...
