
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
- Suggest simple auth flow using just a cu...
Hi...i wanted to know how can we create a auth session using custom id and password. I can give each teacher and student some specific id and corresponding to ...
- Auth showing wrong numbers of users
I have 6 verified users but it shows 5 24 hours before I have 5 users that time its showing 4 users. Project ID: `68aed705001ef67ac979`
- Appwrite + Google OAuth session created,...
Hey everyone, I’m running into a weird issue with Appwrite’s Google OAuth provider and would love some insight. Here’s my setup: - **Stack:** React app...
