loopbackio / loopback-connector-sqlite3

SQLite3 Connector for LoopBack
Other
13 stars 22 forks source link

Does not return proper accessToken #13

Open yuyudhan opened 8 years ago

yuyudhan commented 8 years ago

Sqlite3 connector gives following when logging in: Access token stored in the database is correct, but returned id is the id of accessToken instead of the token itself.

{
  "id": 1,
  "ttl": 1209600,
  "created": "2016-02-22T13:32:31.305Z",
  "userId": 1
}

When using db(in-memory) for storing access tokens it gives following correct result.

{
  "id": "APXMEsHyWmZmXBgi5vAMfWwVfd72nyaXCihskDvqvQILjoliSfGRlcS9MDrtkrrR",
  "ttl": 1209600,
  "created": "2016-02-22T13:33:41.987Z",
  "userId": 1
}
daschewie commented 6 years ago

Hello yuyudhan,

Did you ever figure this out?

yuyudhan commented 6 years ago

No @daschewie , did not try this since long, did not find any solution to it.

vanceeasleaf commented 6 years ago

It seems no body care about this program

HugoPoi commented 6 years ago

I investigate this issue in deep. Sqlite3 has a built-in feature for retrieving the lastID on INSERT statement. It's use here https://github.com/strongloop-community/loopback-connector-sqlite3/blob/master/lib/sqlite3.js#L202 But in the documentation of Sqlite3 https://sqlite.org/c3ref/last_insert_rowid.html the lastID contains the last rowid inserted but when your primary key is not integer you have two primary key : the primary key define in schema and the sqlite3 internal rowid. So when we have on INSERT the lastID=an interger and the real id the token which is override by the dao https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L410.

A solution would be to add WITHOUT ROWID option an the CREATE TABLE for the AccessToken and other model with a string primary key.

For that we need to add model options for this connector. I will start to write a PR this afternoon.

EDIT: WITHOUT ROWID does not solve issue because it returns the last ID inserted on all tables.

HugoPoi commented 6 years ago

My #38 Solve the issue ;-) You can test my PR in your project

"dependencies": {
  "loopback-connector-sqlite3": "git+https://github.com/HugoPoi/loopback-connector-sqlite3.git#faf96a0"
}

But need a review from the admin team. And a release.