Skip to content

Commit

Permalink
Added loginWithToken method.
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalgnlts committed Aug 14, 2022
1 parent da85b74 commit 27d8b95
Show file tree
Hide file tree
Showing 11 changed files with 1,129 additions and 70 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules
node_modules

# FIX: rollup creates ts types files in both dist folder and home directory.
types.d.ts
index.d.ts
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ declare class Mailjs {
register(address: string, password: string): type.RegisterResult;
/** Get an Account resource by its id. */
login(address: string, password: string): type.LoginResult;
/** Login with user JWT token */
loginWithToken(token: string): type.AccountResult;
/** Retrieves a Account resource. */
me(): type.AccountResult;
/** Retrieves a Account resource. */
Expand Down
10 changes: 10 additions & 0 deletions dist/mailjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Mailjs {
}
return res;
}
/** Login with user JWT token */
async loginWithToken(token) {
this.token = token;
const res = await this.me();
if (!res.status)
throw new Error(res.message);
this.id = res.data.id;
this.address = res.data.address;
return res;
}
/** Retrieves a Account resource. */
me() {
return this.send_("/me");
Expand Down
10 changes: 10 additions & 0 deletions dist/mailjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class Mailjs {
}
return res;
}
/** Login with user JWT token */
async loginWithToken(token) {
this.token = token;
const res = await this.me();
if (!res.status)
throw new Error(res.message);
this.id = res.data.id;
this.address = res.data.address;
return res;
}
/** Retrieves a Account resource. */
me() {
return this.send_("/me");
Expand Down
8 changes: 8 additions & 0 deletions examples/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Mailjs = require("../dist/mailjs.js");

const mailjs = new Mailjs();
(async () => {
const login = await mailjs.loginWithToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NjA0Njk0NjIsInJvbGVzIjpbIlJPTEVfVVNFUiJdLCJ1c2VybmFtZSI6IjEwdGN1QGFyeHh3YWxscy5jb20iLCJpZCI6IjYyZjhjMDc3MTI2ZmVkZDFjODAzN2FjNiIsIm1lcmN1cmUiOnsic3Vic2NyaWJlIjpbIi9hY2NvdW50cy82MmY4YzA3NzEyNmZlZGQxYzgwMzdhYzYiXX19.-5VcwrkJjzL6wcGwrDab8R-Y9v6gzGRB8GZJdqmIWQwzpTsWmoEEtJ6v6OAkBsPwa70Dq07buyxcQ27iTtW35w");

console.log(login);
})();
2 changes: 1 addition & 1 deletion mailjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 27d8b95

Please sign in to comment.