Eduardo C. K. Ferreira
Eduardo C. K. Ferreira

Reputation: 374

User Auth in Meteor using an external API

I am building a Meteor app that uses my website login API (built in php) to check if a user is on my website database or not. So using meteor HTTP.post I send user email and password as params, and my website API returns a json with a success or failure message, and that is it.

What I am not being able to do is to, as according to this success message, "login" the user on my Meteor app without creating/checking Users collection from accounts.

So it should be: return success? You are logged in. No users.insert, nor anything like that. Is it possible to be done?

To make this API call, I have created a method, activated here:

Meteor.call('loginUser', userData, function(error, result){
    if(error)
        console.log(error.reason);
    else(console.log(result)) 

    if (result.status == 'ok') {
        Session.set('loginStatus', 'loggedUser');
        Router.go('/');
    }
});

I am using this Session.set only to simulate what I am expecting to happen. But using Session is surelly not the best option.

Upvotes: 1

Views: 460

Answers (1)

gabrielhpugliese
gabrielhpugliese

Reputation: 2588

You must use Accounts.createUser()

http://docs.meteor.com/#/full/accounts_createuser

On client, it will login the user automatically.

Upvotes: 1

Related Questions