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
In addition i've tried
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
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
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...