Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkWith not returns a sessionToken in CloudCloud #9518

Open
puny-d opened this issue Jan 9, 2025 · 1 comment
Open

linkWith not returns a sessionToken in CloudCloud #9518

puny-d opened this issue Jan 9, 2025 · 1 comment

Comments

@puny-d
Copy link

puny-d commented Jan 9, 2025

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

Copy link

Thanks for opening this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant