Skip to content

Commit

Permalink
feat: exposes babel config via payload/babel (#203)
Browse files Browse the repository at this point in the history
* feat: exposes babel config via payload/config

* docs: adds info about re-using babel.config.js
  • Loading branch information
jmikrut committed Jun 21, 2021
1 parent fb60bc7 commit 67c1e28
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 250 deletions.
3 changes: 3 additions & 0 deletions babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const babelConfig = require('./dist/babel.config');

exports.config = babelConfig;
8 changes: 8 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ But, you can specify where your Payload config is located as well as what it's n
The Payload config itself, as well as all files that it requires or imports, are run through Babel. TypeScript and all common ES6 features are fully supported. To see the Babel config that is used to parse Payload configs, check out the Payload source code [here](https://github.com/payloadcms/payload/blob/master/src/babel.config.js).

Payload comes with `isomorphic-fetch` installed which means that even in Node, you can use the `fetch` API just as you would within the browser. No need to import `axios` or similar, unless you want to!

#### Re-using the Payload `babel.config.js`

If for any reason you need to re-use the built-in Payload `babel.config.js`, you can do so by importing it as follows:

```
import { config } from 'payload/babel';
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"*.js",
"*.d.ts",
"!jest.config.js",
"!babel.config.js",
"!jest.react.config.js"
],
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions src/auth/operations/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Collection } from '../../collections/config/types';
export type Result = {
user?: User,
token?: string,
exp?: string,
exp?: number,
}

export type Arguments = {
Expand Down Expand Up @@ -201,7 +201,7 @@ async function login(incomingArgs: Arguments): Promise<Result> {
return {
token,
user,
exp: (jwt.decode(token) as { exp: string }).exp,
exp: (jwt.decode(token) as jwt.JwtPayload).exp,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/auth/operations/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type Result = {
user?: User,
collection?: string,
token?: string,
exp?: string,
exp?: number,
}

export type Arguments = {
Expand Down Expand Up @@ -41,7 +41,7 @@ async function me({

if (token) {
response.token = token;
const decoded = jwt.decode(token) as { exp: string };
const decoded = jwt.decode(token) as jwt.JwtPayload;
if (decoded) response.exp = decoded.exp;
}

Expand Down

0 comments on commit 67c1e28

Please sign in to comment.