Clancey / simple_auth

The Simplest way to Authenticate in Flutter
MIT License
352 stars 108 forks source link

Google : clarification + what is api.send<UserInfo>(request) #88

Closed dylan-dinh closed 5 years ago

dylan-dinh commented 5 years ago

Hello,

what is var userInfo = await api.send<UserInfo>(request); More precisely what is UserInfo ? And what is api.send(request) combined. Because if I get it, you have the user's information in var request. And why do you use await without async ?

Thanks for the clarifications.

Clancey commented 5 years ago

A few things, this is used in a restful style, so UserInfo, is your own model. It matches what the output from the api request should be. It will deal with the de-serialization from Json.

A great example: https://github.com/Clancey/simple_auth/blob/master/simple_auth/lib/src/providers/google.dart#L120-L167 Use this data model and you could change that code to be

var userInfo = await api.send<GoogleUser>("https://www.googleapis.com/oauth2/v1/userinfo?alt=json");

The request is what you want to send. api.Send is where the request is sent to the web server. As for using it without async, thats not possible. Using await is using async.