
Hi guys, can i check if i'm planning to use middleware.ts i'm supposed to use node-appwrite
right? I'm using just the appwrite
one and it doesn't seem to work.
Keeps saying i'm not authenticated while i already am
TL;DR
Developers are experiencing authentication issues when using middleware in NextJS with the 'appwrite' library instead of 'node-appwrite'. It is recommended to use 'node-appwrite' for authentication in middleware.ts.
In addition i've tried
TypeScript
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { appwriteServerAccount } from './lib/server/appwriteServer'
export async function middleware(request: NextRequest) {
if (request.nextUrl.pathname.startsWith('/dashboard')) {
const user = await appwriteServerAccount.get();
console.log(user)
if (!user) {
return NextResponse.redirect(new URL('/login', request.url))
}
}
return NextResponse.next()
}
export const config = {
matcher: ['/dashboard/:path*'],
}
and
TypeScript
import { Account } from 'node-appwrite';
import { Client } from 'node-appwrite';
const appwriteServerClient = new Client();
appwriteServerClient
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID as string)
.setKey(process.env.APPWRITE_SECRET_API_KEY as string);
export const appwriteServerAccount = new Account(appwriteServerClient);
export default appwriteServerClient;
But it still says i'm not authenticated
Recommended threads
- OpenAI Whisper on Appwrite Sites
Hey guys, just wondering if I can serve an OpenAI Whisper AI on appwrite / appwrite sites. tiny model is like ~40-50MB
- Internal curl errors has occurred within...
- There is ui Problem in the Display name
in Display name i have selected buy mistake but when its update that time document get blank and also when i remove at that time also not removing and data is s...
