Back

Validate session on server

  • 0
  • Self Hosted
  • Auth
  • REST API
Meister der Magie | Martin
27 Nov, 2024, 13:54

I develop the server for an educational mobile app. Teachers can log in and then create student accounts for their classes. I have my own ASP .NET server, that's communicating with Appwrite for extended functionality. The app calls the REST endpoint e.g. api.mydomain.com/createStudent. This should then check if the teacher is logged in and if so, create a new account. I have it almost working, except the session validation part.

**How can I check on the Server SDK if a user is logged in? ** Currently I send the session cookie with the http request and then try the following:

TypeScript
Client teacher = new Client()
                .SetEndpoint(AppwriteSettings.Endpoint)
                .SetProject(AppwriteSettings.ProjectId)
                .SetKey(AppwriteSettings.ApiKey)
                .SetSession(sessionCookie);
            
var account = new Account(teacher);
User teacherUser = await account.Get();

This throws a 401 AppwriteException with the message: app.<myProjectId>@service.api.mydomain.com (role: applications) missing scope (account) What am I doing wrong? Isn't the session cookie supposed to be sent with the http request and then authenticate with it on the server side? If not, what's the right way to achieve this?

Thanks in advance for any hint!

TL;DR
Developing educational mobile app server using ASP .NET and Appwrite, struggling to validate sessions. They send session cookie in the HTTP request but encounter a 401 error. The issue might be related to missing scope in the account role. Need help on how to authentically check if a user is logged in on the server side. Solving the missing scope error should fix the problem.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more