Skip to content

linkWith not returns a sessionToken in CloudCloud #9518

Open
@puny-d

Description

@puny-d

I'm encountering an issue with linkWith in Cloud Code on Parse-Server 7.2. When linking a user with a third-party provider, the method does not return a sessionToken as expected. This breaks the intended behavior, where the user should be logged in automatically after linking.

Steps to Reproduce
Here is the code snippet that demonstrates the issue:

Parse.Cloud.define(
  'auth',
  async req => {
    const { authData, nickname, email } = req.params;

    const authName = Object.keys(authData)[0];

    if (!authName) {
      throw new Parse.Error(1000, {
        code: 1001,
        msg: 'invalid authData',
      });
    }
    const provider = getAuthProvider(authName, authData?.[authName]);

    if (!provider) {
      throw new Parse.Error(1000, {
        code: 1001,
        msg: 'invalid authData',
      });
    }

    let hasUser;

    if (email) {
      const query = new Parse.Query(Parse.User);
      query.equalTo('email', email);
      hasUser = await query.first({ useMasterKey: true });
      req.log.info('hasUser', hasUser);
    }

    const user = new Parse.User();

    if (!hasUser) {
      user.set('email', email);
      user.set('nickname', nickname);
    }

    return user.linkWith(provider, authData?.[authName]);

  },
  {
    fields: {
      authData: {
        required: true,
        type: Object,
      },
      nickname: {
        required: true,
        type: String,
      },
      email: {
        type: String,
        options: email => {
          return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,12}$/.test(email);
        },
      },
    },
  }
);

Attempt to link the user with a provider using linkWith.
Observe that no sessionToken is returned.

Environment
Parse Server Version: 7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bounty:$20Bounty applies for fixing this issue (Parse Bounty Program)type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions