Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like sessions in dart?

This may seem like a silly question but I am just starting out with dart and will need to verify user sesions similar to what you might do with PHP with the $_SESSION array...

So I am writing a basic server backend and a frontend and need to authenticate some requests that come in via XMLHttpRequest. The backend sends back JSON based on whether the given frontend is authenticated or not. In some cases, the frontend can update the DOM but only for the user who authenticated.

Not sure if I am explaining this well...

Any advice would be appreciated!!

Thanks!

like image 224
J99 Avatar asked Nov 15 '25 11:11

J99


1 Answers

A session is a high-level functionality that shouldn't be part of any language. You can include session functionality yourself by impelementing something like.

  Map<String, int> sessions = {'abcdef12345' : 42}; // exists in e.g. datastore and is managed by an authentication routine 

  String authenticationToken = 'abcdef12345'; // comes from the request
  if(sessions.containsKey(authenticationToken)) {
    print('User ${sessions[authenticationToken]} is at least authenticated but might not have the appropriate rights to perform this operation.');
  } else {
    print('Not authenticated.');
  }
like image 78
Alex Avatar answered Nov 18 '25 07:11

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!