Web Developer
Hi all, I was looking through the support page for my specific issue but I was unable to find anything that I could adapt for my issue.
I rebuilt my Authentication in the last days after realizing that OAuth Authentication with SSR does not create a providerAccessToken right now. So I now try to create a session with account.createOAuth2Session instead using the Client SDK. Unfortunately, I seem to always get the Error 'User (role: guests) missing scope (account)' although I can see a session for my user in my selfhosted Appwrite as well as a cookie with my project name for my Appwrite Domain.
First off my function for calling createOAuth2Session
"use server"
export async function signUpWithDiscord() {
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT);
const account = new Account(client);
const origin = headers().get("origin");
const redirectUrl = await account.createOAuth2Session(
OAuthProvider.Discord,
`${origin}/auth/oauth2/success`,
`${origin}/auth/oauth2/failure`,
//scopes
);
return redirect(redirectUrl);
};```
After Authentication with Discord, I am redirected to /auth/oauth2/session where I execute the following code:
export async function GET(request) {
const key = request.nextUrl.searchParams.get("key");
const secret = request.nextUrl.searchParams.get("secret");
const origin = headers().get("host");
cookies().set(key, secret, {
domain: origin,
path: "/",
httpOnly: true,
sameSite: "strict",
maxAge: 60 * 60 * 24 * 7,
secure: true,
}); // make the session persistent as a cookie
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT);
const account = new Account(client);
const currsession = await account.getSession('current'); // Here the error occurs
return NextResponse.redirect(${baseURL + "/"});
}
Thanks in advance!