Back

[SOLVED]Deleting session not working

  • 1
  • Flutter
  • Web
  • Databases
  • Self Hosted
  • Users
D5
16 Jun, 2023, 10:04

If you run account.get() in the device you're able to get it?

TL;DR
The user was having trouble deleting a session. They discovered a typo in their code and fixed it. They were also confused about the process of creating and logging in a user. The response suggested that creating a user already gives a session and that using `account.get()` should give a response with user information. The user was also asked to check if running `account.get()` returns any value, indicating if the user is logged in or not. The conversation ended with a suggestion to run `account.get()` on the device to check if it returns any value.
hopeless_
16 Jun, 2023, 10:04

*pnb,it is empty in session tab in user though

D5
16 Jun, 2023, 10:05

Then there's not any active session

hopeless_
16 Jun, 2023, 10:05

can you elaborate a little?

D5
16 Jun, 2023, 10:05

Seems that you are already logged out

D5
16 Jun, 2023, 10:05

Check if running account.get() it returns any value. If it throws an error that means the user has been successfully logged out

hopeless_
16 Jun, 2023, 10:09

but i'm getting session response using this code```var awPhone = servRes['awphone']; Future result = account.createPhoneSession( userId: box.read('user_id_appwrite'), phone: awPhone, );

TypeScript
  result.then((response) {
    print('sessionId ->' + response.$id);
    print('sessionExpire->' + response.expire);
    box.write('sessionId', response.$id);
    // showSuccess('Signup Complete', 'Account created successfully');
    box.write('redirectIndex', true);
    Get.offAllNamed(Routes.HOME);
  }).catchError((error) {
    print(error.response);
    showError('Server Connection Failed',
        'Please check your network connection and try again later');
  });```
hopeless_
16 Jun, 2023, 10:11

awphone is something like +123123123(real country code+phon no)

hopeless_
16 Jun, 2023, 10:45
TypeScript
I/flutter (22032): sessionExpire->2023-06-16T10:59:09.868+00:00
I/flutter (22032): {message: User (role: guests) missing scope (account), code: 401, type: general_unauthorized_scope, version: 0.10.40}```This is when i do accout.get() ater creating phonesession
hopeless_
16 Jun, 2023, 10:45

what's the differnce in account and user

D5
16 Jun, 2023, 10:59

Role guest, means you have a guest account (no logged in)

hopeless_
16 Jun, 2023, 11:00

how to logged in tho?i have created user then i create session,did i miss any procedure?

D5
16 Jun, 2023, 11:01

When you create an user, you already get a session. When using account.get() it should give you a response with the email the account has, name, etc

D5
16 Jun, 2023, 11:02

If after running in your flutter app account.get() it throws you an error, that means the use is not logged in

hopeless_
16 Jun, 2023, 11:11

then how to fix that?πŸ₯Ίi mean how to log in?

D5
16 Jun, 2023, 11:40

account.createEmailSession()

D5
16 Jun, 2023, 11:41

Example in dart:

TypeScript
import 'package:appwrite/appwrite.dart';

void main() { // Init SDK
  Client client = Client();
  Account account = Account(client);

  client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
  ;
  Future result = account.createEmailSession(
    email: 'email@example.com',
    password: 'password',
  );

  result
    .then((response) {
      print(response);
    }).catchError((error) {
      print(error.response);
  });
}
hopeless_
16 Jun, 2023, 11:54

do i need create account with that user first to this(https://appwrite.io/docs/client/account?sdk=flutter-default#accountCreate) or just creating a user is enough (https://appwrite.io/docs/server/users?sdk=php-default#usersCreate)?

hopeless_
16 Jun, 2023, 12:00

Thanks,i have created session successfully but when i delete the session using session ID, i got this error

hopeless_
16 Jun, 2023, 12:00
hopeless_
16 Jun, 2023, 12:03
TypeScript
    ap.Account account = ap.Account(client);

    Future result = account.deleteSession(
      sessionId: box.read('sessionId'),
    );

    result.then((response) {
      print('Session deleted!');
      print(response);
    }).catchError((error) {
      print(error.response);
    });
  }```
hopeless_
16 Jun, 2023, 12:39

Never mind,there was a typo in my code,creating session using email and delete like this works fine!!!

hopeless_
16 Jun, 2023, 12:40

[SOLVED]Deleting session not working

Drake
16 Jun, 2023, 19:58

Btw, this doesn't actually create a session because creating a phone session is a two step process.

See https://appwrite.io/docs/client/account?sdk=flutter-default#accountCreatePhoneSession

And for phone sessions, you don't need to create the account beforehand

hopeless_
17 Jun, 2023, 05:13

oh i see,i have to confirm to session with that OTP, Thanks!<:appwritepeepo:902865250427215882>

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