Possibly ..I don't know too much about Astro...is there any server side code?
well get the same issue alltime if i want to logout i cant acces the "auth" category at my project from the website... logout is not possible... dunno
internal 500 Error code
Here some console error that i get:
AppwriteException: Aborted
Immutable 19
r
call
p
promise callback*f
s
s
call
list
s
s
list
u
de
T
he
ce
re
goto
xt
<anonymous> https://cloud.appwrite.io/console/project-653d12ef8b1934bb1bac/auth:159
promise callback* https://cloud.appwrite.io/console/project-653d12ef8b1934bb1bac/auth:158
app.d2040772.js:1:133492
and here a network analyse seems your api host got rect.
I just have middleware
but running it with Astro on another instance for a different client and it works fine @Steven
do you mean you have the exact same code in another project and it works fine?
middlewares...is that executed server side?
yes
and yes, but all it's doing is redirecting on lack of auth
import { defineMiddleware } from "astro:middleware";
import { $isLoggedIn } from "./store/authStore";
export const onRequest = defineMiddleware(async (context, next) => {
if (context.url.pathname.includes("dashboard")) {
const user = await $isLoggedIn();
if (!user) {
context.redirect("/login");
}
} else if (context.url.pathname.includes("login")) {
const user = await $isLoggedIn();
if (user) {
context.redirect("/dashboard");
}
}
next();
});
my middleware
your session is probably only client side and doesn't exist server side
export const $isLoggedIn = async () => {
try {
const user = await account.get();
if (user) {
const userObject = AuthUser.parse(user);
if (userObject.$id !== $user.get().$id || $user.get() != userObject) {
$user.set(userObject);
}
return true;
} else {
return false;
}
} catch (e: any) {
return false;
}
};
oh
right. That would do that. But it's not redirecting me
do you need to call return after context.redirect()?
else, that next() would execute, right?
Hm, maybe, but I really don't think the middleware is causing it, but maybe, I don't know why that would interfere with my client side though?
@Steven still can't figure this out, here's all of the relevant
code
const client = new Client()
.setEndpoint("https://myapprwite.com/v1")
.setProject("myproject");
export const account = new Account(client);
export const database = new Databases(client);
export const functions = new Functions(client);
export const $createDocument = async (
collectionId: string,
data: any,
docId?: string
) => {
try {
let id = docId || ID.unique();
const document = await database.createDocument(
"maindb",
collectionId,
id,
data
);
return document;
} catch (e: any) {
console.error(e);
return null;
}
};
export const $getDocument = async (collectionId: string, docId: string) => {
try {
const document = await database.getDocument("maindb", collectionId, docId);
return document;
} catch (e: any) {
console.error(e);
return null;
}
};
export const $loginUser = async (email: string, password: string) => {
try {
const user = await account.createEmailSession(email, password);
await $isLoggedIn();
return true;
} catch (e: any) {
console.error(e);
return null;
}
};
const isLoggedIn = await $isLoggedIn();
if (isLoggedIn) {
const userPrefs = await account.getPrefs();
if (!(userPrefs.bio && userPrefs.bio.length > 0)) {
needBio.value = true;
loaded.value = true;
} else {
needBio.value = false;
userBio.value = userPrefs.bio;
isUserAdmin.value = userPrefs.isAdmin ? true : false;
const existingChat = await $getCurrentChat();
if (
curChat.value.userId &&
curChat.value.userId.length > 0 &&
curChat.value.$id.length > 0 &&
!loaded.value
) {
console.log("Getting current chat");
if (!existingChat) {
console.log("Creating chat");
await createChat();
} else {
console.log("Getting current chat messages");
await $getCurrentChatMessages();
}
} else {
console.log("Current chat failed to load: ", curChat.value);
}
loaded.value = true;
console.log("Loaded user prefs");
}
} else {
console.error("User not logged in");
needsRedirectToLogin.value = true;
}
I really don't understand why when it was working perfectly fine yesterday, I even logged in <a:spinning_think:400736652089360394>
okay so
it works now, no idea why, I'm gonna close this, there's an issue with something else but that's on me
[SOLVED] User (role: guests) missing scope (account) but I'm signed in...?
Recommended threads
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- apple exchange code to token
hello guys, im new here 🙂 I have created a project and enabled apple oauth, filled all data (client id, key id, p8 file itself etc). I generate oauth code form...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...