Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: exposes babel config via payload/babel #203

Merged
merged 5 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading