make dev setup better (#116)
* make dev setup better * chage docs * remove the need of github login
This commit is contained in:
@@ -289,16 +289,17 @@ model Campaign {
|
||||
}
|
||||
|
||||
model Template {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
teamId Int
|
||||
subject String
|
||||
html String?
|
||||
content String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
teamId Int
|
||||
subject String
|
||||
html String?
|
||||
content String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([createdAt(sort: Desc)])
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { env } from "~/env";
|
||||
import { db } from "~/server/db";
|
||||
import { parseSesHook, SesHookParser } from "~/server/service/ses-hook-parser";
|
||||
import { SesSettingsService } from "~/server/service/ses-settings-service";
|
||||
@@ -83,6 +84,10 @@ async function handleSubscription(message: any) {
|
||||
* A simple check to ensure that the event is from the correct topic
|
||||
*/
|
||||
async function checkEventValidity(message: SnsNotificationMessage) {
|
||||
if (env.NODE_ENV === "development") {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { TopicArn } = message;
|
||||
const configuredTopicArn = await SesSettingsService.getTopicArns();
|
||||
|
||||
|
@@ -17,6 +17,7 @@ import { Input } from "@unsend/ui/src/input";
|
||||
import { Button } from "@unsend/ui/src/button";
|
||||
import Spinner from "@unsend/ui/src/spinner";
|
||||
import { toast } from "@unsend/ui/src/toaster";
|
||||
import { isLocalhost } from "~/utils/client";
|
||||
|
||||
const FormSchema = z.object({
|
||||
region: z.string(),
|
||||
@@ -65,14 +66,16 @@ export const AddSesSettingsForm: React.FC<SesSettingsProps> = ({
|
||||
});
|
||||
|
||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||
if (!data.unsendUrl.startsWith("https://")) {
|
||||
const localhost = isLocalhost();
|
||||
|
||||
if (!data.unsendUrl.startsWith("https://") && !localhost) {
|
||||
form.setError("unsendUrl", {
|
||||
message: "URL must start with https://",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.unsendUrl.includes("localhost")) {
|
||||
if (data.unsendUrl.includes("localhost") && !localhost) {
|
||||
form.setError("unsendUrl", {
|
||||
message: "URL must be a valid url",
|
||||
});
|
||||
|
@@ -29,14 +29,15 @@ export const env = createEnv({
|
||||
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
|
||||
process.env.VERCEL ? z.string() : z.string().url()
|
||||
),
|
||||
GITHUB_ID: z.string(),
|
||||
GITHUB_SECRET: z.string(),
|
||||
GITHUB_ID: z.string().optional(),
|
||||
GITHUB_SECRET: z.string().optional(),
|
||||
AWS_ACCESS_KEY: z.string(),
|
||||
AWS_SECRET_KEY: z.string(),
|
||||
UNSEND_API_KEY: z.string().optional(),
|
||||
GOOGLE_CLIENT_ID: z.string().optional(),
|
||||
GOOGLE_CLIENT_SECRET: z.string().optional(),
|
||||
AWS_SES_ENDPOINT: z.string().optional(),
|
||||
AWS_SNS_ENDPOINT: z.string().optional(),
|
||||
AWS_DEFAULT_REGION: z.string().default("us-east-1"),
|
||||
API_RATE_LIMIT: z
|
||||
.string()
|
||||
@@ -83,6 +84,7 @@ export const env = createEnv({
|
||||
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
|
||||
AWS_DEFAULT_REGION: process.env.AWS_DEFAULT_REGION,
|
||||
AWS_SES_ENDPOINT: process.env.AWS_SES_ENDPOINT,
|
||||
AWS_SNS_ENDPOINT: process.env.AWS_SNS_ENDPOINT,
|
||||
API_RATE_LIMIT: process.env.API_RATE_LIMIT,
|
||||
NEXT_PUBLIC_IS_CLOUD: process.env.NEXT_PUBLIC_IS_CLOUD,
|
||||
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
|
||||
|
@@ -44,13 +44,17 @@ declare module "next-auth" {
|
||||
* Auth providers
|
||||
*/
|
||||
|
||||
const providers: Provider[] = [
|
||||
GitHubProvider({
|
||||
clientId: env.GITHUB_ID,
|
||||
clientSecret: env.GITHUB_SECRET,
|
||||
allowDangerousEmailAccountLinking: true,
|
||||
}),
|
||||
];
|
||||
const providers: Provider[] = [];
|
||||
|
||||
if (env.GITHUB_ID && env.GITHUB_SECRET) {
|
||||
providers.push(
|
||||
GitHubProvider({
|
||||
clientId: env.GITHUB_ID,
|
||||
clientSecret: env.GITHUB_SECRET,
|
||||
allowDangerousEmailAccountLinking: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET) {
|
||||
providers.push(
|
||||
@@ -76,6 +80,10 @@ if (env.FROM_EMAIL) {
|
||||
);
|
||||
}
|
||||
|
||||
if (providers.length === 0) {
|
||||
throw new Error("No auth providers found, need atleast one");
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
|
||||
*
|
||||
@@ -100,7 +108,7 @@ export const authOptions: NextAuthOptions = {
|
||||
events: {
|
||||
createUser: async ({ user }) => {
|
||||
// No waitlist for self hosting
|
||||
if (!env.NEXT_PUBLIC_IS_CLOUD) {
|
||||
if (!env.NEXT_PUBLIC_IS_CLOUD || env.NODE_ENV === "development") {
|
||||
await db.user.update({
|
||||
where: { id: user.id },
|
||||
data: { isBetaUser: true },
|
||||
|
@@ -8,6 +8,7 @@ import { env } from "~/env";
|
||||
|
||||
function getSnsClient(region: string) {
|
||||
return new SNSClient({
|
||||
endpoint: env.AWS_SNS_ENDPOINT,
|
||||
region: region,
|
||||
credentials: {
|
||||
accessKeyId: env.AWS_ACCESS_KEY,
|
||||
@@ -44,6 +45,5 @@ export async function subscribeEndpoint(
|
||||
const client = getSnsClient(region);
|
||||
|
||||
const data = await client.send(subscribeCommand);
|
||||
console.log(data.SubscriptionArn);
|
||||
return data.SubscriptionArn;
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ export async function sendSignUpEmail(
|
||||
const { host } = new URL(url);
|
||||
|
||||
if (env.NODE_ENV === "development") {
|
||||
console.log("Sending sign in email", email, url, token);
|
||||
console.log("Sending sign in email", { email, url, token });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -131,9 +131,10 @@ export class SesSettingsService {
|
||||
try {
|
||||
await sns.deleteTopic(topicArn, region);
|
||||
} catch (deleteError) {
|
||||
console.error('Failed to delete SNS topic after error:', deleteError);
|
||||
console.error("Failed to delete SNS topic after error:", deleteError);
|
||||
}
|
||||
}
|
||||
console.error("Failed to create SES setting", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
3
apps/web/src/utils/client.ts
Normal file
3
apps/web/src/utils/client.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const isLocalhost = () => {
|
||||
return location.hostname === "localhost";
|
||||
};
|
Reference in New Issue
Block a user