Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit fb84a2d

Browse files
author
Maricris Bonzo
committed
fix env
1 parent 8b4d0d6 commit fb84a2d

9 files changed

+2531
-752
lines changed

.env.example

-3
This file was deleted.

.env.local.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NEXT_PUBLIC_MAGIC_TEST_PUBLISHABLE_KEY=pk_test_XXXXX
2+
NEXT_PUBLIC_MAGIC_TEST_SECRET_KEY=sk_test_XXXXX
3+
NEXT_PUBLIC_HAPI_IRON_SECRET=this-is-a-secret-value-with-at-least-32-characters

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ yarn-debug.log*
2525
yarn-error.log*
2626

2727
# local env files
28-
.env
2928
.env.local
3029
.env.development.local
3130
.env.test.local
3231
.env.production.local
3332

34-
# next.js config files
35-
next.config.js
36-
3733
# vercel
3834
.vercel

lib/auth.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
import Iron from '@hapi/iron'
2-
import { MAX_AGE, setTokenCookie, getTokenCookie } from './auth-cookies'
1+
import Iron from "@hapi/iron";
2+
import { MAX_AGE, setTokenCookie, getTokenCookie } from "./auth-cookies";
33

4-
const HAPI_IRON_SECRET = process.env.HAPI_IRON_SECRET
4+
const HAPI_IRON_SECRET = process.env.NEXT_PUBLIC_HAPI_IRON_SECRET;
55

66
export async function setLoginSession(res, session) {
7-
const createdAt = Date.now()
7+
const createdAt = Date.now();
88
// Create a session object with a max age that we can validate later
9-
const obj = { ...session, createdAt, maxAge: MAX_AGE }
10-
const token = await Iron.seal(obj, HAPI_IRON_SECRET, Iron.defaults)
11-
12-
setTokenCookie(res, token)
9+
const obj = { ...session, createdAt, maxAge: MAX_AGE };
10+
const token = await Iron.seal(
11+
obj,
12+
HAPI_IRON_SECRET,
13+
Iron.defaults
14+
);
15+
16+
setTokenCookie(res, token);
1317
}
1418

1519
export async function getLoginSession(req) {
16-
const token = getTokenCookie(req)
20+
const token = getTokenCookie(req);
1721

18-
if (!token) return
22+
if (!token) return;
1923

20-
const session = await Iron.unseal(token, HAPI_IRON_SECRET, Iron.defaults)
21-
const expiresAt = session.createdAt + session.maxAge * 1000
24+
const session = await Iron.unseal(
25+
token,
26+
HAPI_IRON_SECRET,
27+
Iron.defaults
28+
);
29+
const expiresAt = session.createdAt + session.maxAge * 1000;
2230

2331
// Validate the expiration date of the session
2432
if (Date.now() > expiresAt) {
25-
throw new Error('Session expired')
33+
throw new Error("Session expired");
2634
}
2735

28-
return session
36+
return session;
2937
}

lib/magic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const { Magic } = require('@magic-sdk/admin')
22

3-
export const magic = new Magic(process.env.MAGIC_TEST_SECRET_KEY)
3+
export const magic = new Magic(process.env.NEXT_PUBLIC_MAGIC_TEST_SECRET_KEY)

next.config.example.js

-7
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@magic-sdk/admin": "1.0.0",
1111
"cookie": "0.4.0",
1212
"magic-sdk": "1.0.1",
13-
"next": "latest",
13+
"next": "9.4.0",
1414
"react": "latest",
1515
"react-dom": "latest",
1616
"swr": "0.1.16"

pages/login.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Login = () => {
2323
const lifespan = 60 * 60 * 8; // Lifespan of the access token is 8 hours
2424

2525
try {
26-
const magic = new Magic(process.env.MAGIC_TEST_PUBLISHABLE_KEY);
26+
const magic = new Magic(process.env.NEXT_PUBLIC_MAGIC_TEST_PUBLISHABLE_KEY);
2727
await magic.auth.loginWithMagicLink({
2828
email: body.email,
2929
});

0 commit comments

Comments
 (0)