Monday, 29 October 2018

Javascript fetch Cookie not set in Chrome and Firefox for iPhone

i'm trying to understand this behaviour for a university project.

I've a react web application deployed on google cloud and a Go server also deployed on google cloud.

The web application uses the API served by my Go server.

The app seems to work pretty well using Chrome and Firefox browsers in a desktop environment and on Android smartphones but when i use it with the same browsers on iOS (iPhone8) the API calls do not contain the cookie i need to authenticate the user in my Go server. Safari also does work good, so i see this behaviour only with Chrome and Firefox on my iPhone

These are the headers of two calls at the same API, the first made with Safari and the second made with Firefox:

Safari (iOS 12.0.1)

GET /example/users HTTP/1.1
Host: api-server.com
Connection: close
Accept-Language: en-gb
Cookie: default=MTU0MDM3MTA0... /*COOKIE IS SET HERE*/
Dnt: 1
Origin: https://example.com
Referer: https://example.com/
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_0_1 like Mac OS X) 
            AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 
            Mobile/15E148 Safari/604.1
X-Cloud-Trace-Context: 38640...

Firefox (v14.0)

GET /example/users HTTP/1.1
Host: api-server.com
Connection: close
Accept-Language: en-gb
Origin: https://example.com
Referer: https://example.com/
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_0_1 like Mac OS X) 
            AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/14.0b12646 
            Mobile/16A404 Safari/605.1.15
X-Cloud-Trace-Context: cb5ff...

When i send the request using fetch, i set the option credentials: 'include' but as you can see the second call does not set the cookie i need...

What am i missing?

Thank you for your help



from Javascript fetch Cookie not set in Chrome and Firefox for iPhone

Node.js sequelize model - can I define order of records on the model?

I am newish to node, and can't figure out how to only return 1 record of a hasMany relationship, based on an attribute.

There's a user, level, and levels_user table. On user, I want to include 1 levels_user where level_id is highest.

Can I put a condition on this model file, something like:

order_by: ['level_id', 'DESC']

LevelsUsers Model

  'use strict';
  module.exports = (sequelize, DataTypes) => {

    let LevelsUsers = sequelize.define('LevelsUsers', {
        user_id: DataTypes.INTEGER,
        level_id: DataTypes.INTEGER,
        created_at: DataTypes.DATE,
        updated_at: DataTypes.DATE,
    },{
        timestamps: false,
        freezeTableName: true,
        schema: "public",
        tableName: "levels_users"
    });


    return LevelsUsers;
};

Users model association:

    Users.hasMany(models.LevelsUsers, {
        as: 'levels_users',
        targetKey: 'id',
        foreignKey: 'user_id',
    });

This is my call:

users.getProfileByUserId = (req, res) => {
    models.Users.findOne({
      where: {id: req.params.userid},
      include: [
        {
          model: models.LevelsUsers,
          as: 'levels_users',
          limit: 1,
        }
      ]
      order: []
   }).then(user ....

I tried adding:

     `order: [
        [ models.LevelsUsers , 'level_id', 'DESC']
      ]`

Did not work and I think it's evaluated after limit: 1 anyways.

Can I put order_by on the model, to return highest to lowest by level_id each time? If not, what's a better way to accomplish returning only the highest levels_users record where level_id is highest?



from Node.js sequelize model - can I define order of records on the model?

Faces indexed by iOS/Android app are not detected by Android/iOS App - AWS Rekognition

So I have been working on a product (Android First and then iOS) for a long time that index faces of people using AWS Rekognition and when they are again scanned later, it identifies them. It's working great when I index a face from an Android device and then try to search it with an Android device. But if I try to search it later on iOS app, it doesn't find it. Same is the result if I go other way round. Index with iOS, search with Android, not found. The collection ID is same while indexing and searching on both devices. I couldn't figure out how is it possible that a face indexed by one OS type, same region, same collection, couldn't be found while on other device.

If anyone here could try and help me with the issue, please do. I'll be really thankful.

Update 1: I have called "listCollections" function on both iOS and android apps. Both of them are showing different list of collections. This is the issue. But I can't figure our why it is happening. The identity pool and region is same on both of them.



from Faces indexed by iOS/Android app are not detected by Android/iOS App - AWS Rekognition