lundi 19 août 2019

Is it a correct way to implement ember-simple-auth authentication with graphql?

I have a graphql request. The request is working and it returns a token for a particular user. But I am not sure how to utilize that token with ember-simple-auth and its sessions. I've used just this: this.set("session.isAuthenticated", true). Using it, it seems to be that the application don't need to use authenticator at all. I am not sure about this decision and want to ask maybe there is a better way to use ember-simple-auth in this situation (when I get the token through graphql request and don't need to use authenticator). Also I wanted to ask whether I can save the token this way: this.set("sssion.token", token), or there's an "idiomatic" (built in) solution?

I've tried to use authenticator in a different ways, but it wasn't working. As I understand it is supposed to send POST-request on backend, but since there already is a graphql request, probably it means the application don't need authenticator, only session service is necessary. Are there some draw-backs in this decision?

My login.js file in controllers folder looks like this:

    actions: {
        authenticate() {
            let username = this.get('email');
            let password = this.get('password');
            let hash = {username: username, password: password };

            let controller = this;
            this.get('apollo').mutate({mutation: Mutation.TOKEN_AUTH, variables: hash})
            .then(function(result) {
                controller.set('session.isAuthenticated', true);
                console.log('session.isAuthenticated: ', controller.get('session.isAuthenticated'));
            })
            .catch(function(reason) {
                console.log('Error: ', reason);
            })

I've got "func is not defined" error in browser console, but not sure whether it's related to this problem.




Aucun commentaire:

Enregistrer un commentaire