Coder Social home page Coder Social logo

Setting a token about mailjs HOT 5 CLOSED

cemalgnlts avatar cemalgnlts commented on June 18, 2024
Setting a token

from mailjs.

Comments (5)

mr-akashdesai avatar mr-akashdesai commented on June 18, 2024 1

Sure, no worries, I was just wondering. Thanks for the help. 🙂

from mailjs.

cemalgnlts avatar cemalgnlts commented on June 18, 2024 1

If anyone is wondering, there is a method for this now. 27d8b95

from mailjs.

cemalgnlts avatar cemalgnlts commented on June 18, 2024

Hi,

There is currently no feature for this. But you can directly forward the token to the created instance.

const mailjs = new Mailjs();
mailjs.token = "MY_TOKEN";

This method will not give you the user ID and address so to solve this problem you will need a function to give the id and address information after issuing the token.

async function loginWithToken(token) {
  const mailjs = new Mailjs();
  mailjs.token = token;

  const res = await mailjs.me();

  // Throw the error message if the request failed.
  if(!res.status) throw new Error(res.message);

  mailjs.id = res.data.id;
  mailjs.address = res.data.address;

  return mailjs;
}

function loginSuccess(mailjs) {
  // mailjs maintains an authorized instance.
}

loginWithToken("MY_TOKEN")
  .then(loginSuccess)
  .catch(console.error)

I hope this will work for you.

from mailjs.

mr-akashdesai avatar mr-akashdesai commented on June 18, 2024

Hi,

Yeah so this was my initial plan to set the token however as I mentioned, the token has a private type assigned to it, so you can't overwrite it. Not sure if this is a bug with the TypeScript typings, but this is what I get when I try to override the token. This is why I wasn't sure if it was possible or not.

image

image

from mailjs.

cemalgnlts avatar cemalgnlts commented on June 18, 2024

Yes, you are right.
I added TypeScript to the project later, I don't remember why I used it with private. Maybe I can add a new function.

But overriding TypeScript for that line might be a workaround.

// @ts-ignore:next-line

from mailjs.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.