Skip to content

Commit

Permalink
fix dev-autologin, small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed Jan 16, 2024
1 parent 201e7a4 commit 223ac04
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ PAYLOAD_DATABASE_URL="mongodb://127.0.0.1/payload"
PAYLOAD_SECRET="verysecretkey"
PAYLOAD_REVALIDATION_KEY="veryprivatekey"
PAYLOAD_PORT=3001
PAYLOAD_DEVELOPMENT_AUTOLOGIN_EMAIL=[email protected]
PAYLOAD_DEVELOPMENT_AUTOLOGIN_PASSWORD=root
PAYLOAD_LOCAL_DEVELOPMENT=true
# for LOCAL_DEVELOPMENT autologin setup, DO NOT USE IN PRODUCTION :)
PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_EMAIL=[email protected]
PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_PASSWORD=root
PAYLOAD_PUBLIC_LOCAL_DEVELOPMENT=true

NEXT_REVALIDATION_KEY="veryprivatekey"

Expand Down
19 changes: 10 additions & 9 deletions apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ import { Footer } from "./globals/footer";
import { LandingPage } from "./globals/landing-page";
import { MainNavigation } from "./globals/main-navigation";

const { CLIENT_ID, CLIENT_SECRET, MONGODB_URI, PUBLIC_FRONTEND_URL } =
process.env;

declare module "payload" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- not applicable
export interface GeneratedTypes extends Config {}
}

const {
CLIENT_ID,
CLIENT_SECRET,
MONGODB_URI,
PUBLIC_FRONTEND_URL,
AZURE_STORAGE_CONNECTION_STRING,
AZURE_STORAGE_CONTAINER_NAME,
AZURE_STORAGE_ACCOUNT_BASEURL,
} = process.env;

const useCloudStorage =
typeof AZURE_STORAGE_CONNECTION_STRING === "string" &&
typeof AZURE_STORAGE_CONTAINER_NAME === "string" &&
Expand All @@ -40,12 +41,12 @@ export default buildConfig({
bundler: webpackBundler(),
user: Users.slug,
autoLogin:
process.env.PAYLOAD_LOCAL_DEVELOPMENT === "true" &&
process.env.PAYLOAD_DEVELOPMENT_AUTOLOGIN_EMAIL &&
process.env.PAYLOAD_DEVELOPMENT_AUTOLOGIN_PASSWORD
process.env.PAYLOAD_PUBLIC_LOCAL_DEVELOPMENT === "true" &&
process.env.PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_EMAIL &&
process.env.PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_PASSWORD
? {
email: process.env.PAYLOAD_DEVELOPMENT_AUTOLOGIN_EMAIL,
password: process.env.PAYLOAD_DEVELOPMENT_AUTOLOGIN_PASSWORD,
email: process.env.PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_EMAIL,
password: process.env.PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_PASSWORD,
}
: false,
},
Expand Down
10 changes: 5 additions & 5 deletions apps/cms/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const app = express();
app.get("/", (_, res) => {
res.redirect("/admin");
});

const start = async (): Promise<void> => {
// Initialize Payload
await payload.init({
Expand All @@ -22,12 +21,13 @@ const start = async (): Promise<void> => {
payloadInstance.logger.info(
`Payload Admin URL: ${payloadInstance.getAdminURL()}`,
);
if (process.env.PAYLOAD_LOCAL_DEVELOPMENT === "true") {
const email = process.env.PAYLOAD_DEVELOPMENT_AUTOLOGIN_EMAIL;
const password = process.env.PAYLOAD_DEVELOPMENT_AUTOLOGIN_PASSWORD;
if (process.env.PAYLOAD_PUBLIC_LOCAL_DEVELOPMENT === "true") {
const email = process.env.PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_EMAIL;
const password =
process.env.PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_PASSWORD;
if (!email || !password) {
throw new Error(
"PAYLOAD_DEVELOPMENT_AUTOLOGIN_EMAIL and PAYLOAD_DEVELOPMENT_AUTOLOGIN_PASSWORD must be set when PAYLOAD_LOCAL_DEVELOPMENT is true",
"PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_EMAIL and PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_PASSWORD must be set when PAYLOAD_PUBLIC_LOCAL_DEVELOPMENT is true",
);
}
// check if the user exists, if not, create it
Expand Down
6 changes: 3 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"PAYLOAD_SECRET",
"PAYLOAD_REVALIDATION_KEY",
"PAYLOAD_PORT",
"PAYLOAD_DEVELOPMENT_AUTOLOGIN_EMAIL",
"PAYLOAD_DEVELOPMENT_AUTOLOGIN_PASSWORD",
"PAYLOAD_LOCAL_DEVELOPMENT",
"PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_EMAIL",
"PAYLOAD_PUBLIC_DEVELOPMENT_AUTOLOGIN_PASSWORD",
"PAYLOAD_PUBLIC_LOCAL_DEVELOPMENT",
"NEXT_REVALIDATION_KEY",
"PUBLIC_FRONTEND_URL",
"PUBLIC_SERVER_URL"
Expand Down

0 comments on commit 223ac04

Please sign in to comment.