Relayjs Graphql user authentication -


is possible authenticate users different roles solely trough graphql server in combination relay & react?

i looked around, , couldn't find info topic.

in current setup, login features different roles, still going trough traditional rest api... ('secured' json web tokens).

i did in 1 of app, need user interface, 1 return null on first root query if nobody logged in, , can update login mutation passing in credentials. main problem cookies or session inside post relay request since does'nt handle cookie field in request.

here client mutation:

 export default class loginmutation extends relay.mutation {   static fragments = {     user: () => relay.ql`       fragment on user {         id,         mail       }     `,   };   getmutation() {     return relay.ql`mutation{login}`;   }    getvariables() {     return {       mail: this.props.credentials.pseudo,       password: this.props.credentials.password,     };   }   getconfigs() {     return [{       type: 'fields_change',       fieldids: {         user: this.props.user.id,       }     }];   }   getoptimisticresponse() {     return {       mail: this.props.credentials.pseudo,     };   }   getfatquery() {     return relay.ql`     fragment on loginpayload {       user {         userid,         mail       }     }     `;   } } 

and here schema side mutation

var loginmutation = mutationwithclientmutationid({   name: 'login',   inputfields: {     mail: {       type: new graphqlnonnull(graphqlstring)     },     password: {       type: new graphqlnonnull(graphqlstring)     }   },   outputfields: {     user: {       type: graphqluser,       resolve: (newuser) => newuser     }   },   mutateandgetpayload: (credentials, {     rootvalue   }) => co(function*() {     var newuser = yield getuserbycredentials(credentials, rootvalue);     console.log('schema:loginmutation');     delete newuser.id;     return newuser;   }) }); 

to keep users logged through page refresh send own request , fill cookie field... way make work...


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -