Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

tingy tings

Chris Bautistaa5c5503fd6b3
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index 486b190d..60643047 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -30,6 +30,8 @@ const config = {
],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-empty-interface": "off",
+ "@typescript-eslint/no-non-null-assertion": "off",
+ "@typescript-eslint/no-explicit-any": "off",
},
};
diff --git a/package-lock.json b/package-lock.json
index b1ea80b1..763beeda 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10,6 +10,7 @@
"hasInstallScript": true,
"dependencies": {
"@clerk/nextjs": "^4.19.0",
+ "@next-auth/prisma-adapter": "^1.0.6",
"@prisma/client": "^4.14.0",
"@radix-ui/react-navigation-menu": "^1.1.3",
"@radix-ui/react-slot": "^1.0.2",
@@ -23,6 +24,7 @@
"clsx": "^1.2.1",
"lucide-react": "^0.224.0",
"next": "^13.4.2",
+ "next-auth": "^4.22.1",
"next-themes": "^0.2.1",
"react": "18.2.0",
"react-dom": "18.2.0",
@@ -347,6 +349,15 @@
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz",
"integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
},
+ "node_modules/@next-auth/prisma-adapter": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/@next-auth/prisma-adapter/-/prisma-adapter-1.0.6.tgz",
+ "integrity": "sha512-Z7agwfSZEeEcqKqrnisBun7VndRPshd6vyDsoRU68MXbkui8storkHgvN2hnNDrqr/hSCF9aRn56a1qpihaB4A==",
+ "peerDependencies": {
+ "@prisma/client": ">=2.26.0 || >=3",
+ "next-auth": "^4"
+ }
+ },
"node_modules/@next/env": {
"version": "13.4.4",
"resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.4.tgz",
@@ -528,6 +539,14 @@
"node": ">= 8"
}
},
+ "node_modules/@panva/hkdf": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.1.1.tgz",
+ "integrity": "sha512-dhPeilub1NuIG0X5Kvhh9lH4iW3ZsHlnzwgwbOlgwQ2wG1IqFzsgHqmKPk3WzsdWAeaxKJxgM0+W433RmN45GA==",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/@peculiar/asn1-schema": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.3.6.tgz",
@@ -3822,6 +3841,14 @@
"jiti": "bin/jiti.js"
}
},
+ "node_modules/jose": {
+ "version": "4.14.4",
+ "resolved": "https://registry.npmjs.org/jose/-/jose-4.14.4.tgz",
+ "integrity": "sha512-j8GhLiKmUAh+dsFXlX1aJCbt5KMibuKb+d7j1JaOJG6s2UjX1PQlW+OKB/sD4a/5ZYF4RcmYmLSndOoU3Lt/3g==",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -3961,7 +3988,6 @@
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
- "dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
@@ -4159,6 +4185,33 @@
}
}
},
+ "node_modules/next-auth": {
+ "version": "4.22.1",
+ "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.22.1.tgz",
+ "integrity": "sha512-NTR3f6W7/AWXKw8GSsgSyQcDW6jkslZLH8AiZa5PQ09w1kR8uHtR9rez/E9gAq/o17+p0JYHE8QjF3RoniiObA==",
+ "dependencies": {
+ "@babel/runtime": "^7.20.13",
+ "@panva/hkdf": "^1.0.2",
+ "cookie": "^0.5.0",
+ "jose": "^4.11.4",
+ "oauth": "^0.9.15",
+ "openid-client": "^5.4.0",
+ "preact": "^10.6.3",
+ "preact-render-to-string": "^5.1.19",
+ "uuid": "^8.3.2"
+ },
+ "peerDependencies": {
+ "next": "^12.2.5 || ^13",
+ "nodemailer": "^6.6.5",
+ "react": "^17.0.2 || ^18",
+ "react-dom": "^17.0.2 || ^18"
+ },
+ "peerDependenciesMeta": {
+ "nodemailer": {
+ "optional": true
+ }
+ }
+ },
"node_modules/next-themes": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.2.1.tgz",
@@ -4256,6 +4309,11 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/oauth": {
+ "version": "0.9.15",
+ "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz",
+ "integrity": "sha512-a5ERWK1kh38ExDEfoO6qUHJb32rd7aYmPHuyCu3Fta/cnICvYmgd2uhuKXvPD+PXB+gCEYYEaQdIRAjCOwAKNA=="
+ },
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@@ -4264,6 +4322,14 @@
"node": ">=0.10.0"
}
},
+ "node_modules/object-hash": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz",
+ "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==",
+ "engines": {
+ "node": ">= 6"
+ }
+ },
"node_modules/object-inspect": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",
@@ -4377,6 +4443,14 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/oidc-token-hash": {
+ "version": "5.0.3",
+ "resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz",
+ "integrity": "sha512-IF4PcGgzAr6XXSff26Sk/+P4KZFJVuHAJZj3wgO3vX2bMdNVp/QXTP3P7CEm9V1IdG8lDLY3HhiqpsE/nOwpPw==",
+ "engines": {
+ "node": "^10.13.0 || >=12.0.0"
+ }
+ },
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -4418,6 +4492,20 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/openid-client": {
+ "version": "5.4.2",
+ "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.4.2.tgz",
+ "integrity": "sha512-lIhsdPvJ2RneBm3nGBBhQchpe3Uka//xf7WPHTIglery8gnckvW7Bd9IaQzekzXJvWthCMyi/xVEyGW0RFPytw==",
+ "dependencies": {
+ "jose": "^4.14.1",
+ "lru-cache": "^6.0.0",
+ "object-hash": "^2.2.0",
+ "oidc-token-hash": "^5.0.3"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/optionator": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
@@ -4678,6 +4766,26 @@
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
},
+ "node_modules/preact": {
+ "version": "10.15.1",
+ "resolved": "https://registry.npmjs.org/preact/-/preact-10.15.1.tgz",
+ "integrity": "sha512-qs2ansoQEwzNiV5eAcRT1p1EC/dmEzaATVDJNiB3g2sRDWdA7b7MurXdJjB2+/WQktGWZwxvDrnuRFbWuIr64g==",
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/preact"
+ }
+ },
+ "node_modules/preact-render-to-string": {
+ "version": "5.2.6",
+ "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.6.tgz",
+ "integrity": "sha512-JyhErpYOvBV1hEPwIxc/fHWXPfnEGdRKxc8gFdAZ7XV4tlzyzG847XAyEZqoDnynP88akM4eaHcSOzNcLWFguw==",
+ "dependencies": {
+ "pretty-format": "^3.8.0"
+ },
+ "peerDependencies": {
+ "preact": ">=10"
+ }
+ },
"node_modules/prelude-ls": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
@@ -4772,6 +4880,11 @@
}
}
},
+ "node_modules/pretty-format": {
+ "version": "3.8.0",
+ "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz",
+ "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew=="
+ },
"node_modules/prisma": {
"version": "4.14.1",
"resolved": "https://registry.npmjs.org/prisma/-/prisma-4.14.1.tgz",
@@ -5791,6 +5904,14 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
+ "node_modules/uuid": {
+ "version": "8.3.2",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
+ "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
+ "bin": {
+ "uuid": "dist/bin/uuid"
+ }
+ },
"node_modules/webcrypto-core": {
"version": "1.7.7",
"resolved": "https://registry.npmjs.org/webcrypto-core/-/webcrypto-core-1.7.7.tgz",
@@ -5886,8 +6007,7 @@
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
- "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
- "dev": true
+ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/yaml": {
"version": "2.3.1",
@@ -6153,6 +6273,12 @@
}
}
},
+ "@next-auth/prisma-adapter": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/@next-auth/prisma-adapter/-/prisma-adapter-1.0.6.tgz",
+ "integrity": "sha512-Z7agwfSZEeEcqKqrnisBun7VndRPshd6vyDsoRU68MXbkui8storkHgvN2hnNDrqr/hSCF9aRn56a1qpihaB4A==",
+ "requires": {}
+ },
"@next/env": {
"version": "13.4.4",
"resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.4.tgz",
@@ -6244,6 +6370,11 @@
"fastq": "^1.6.0"
}
},
+ "@panva/hkdf": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.1.1.tgz",
+ "integrity": "sha512-dhPeilub1NuIG0X5Kvhh9lH4iW3ZsHlnzwgwbOlgwQ2wG1IqFzsgHqmKPk3WzsdWAeaxKJxgM0+W433RmN45GA=="
+ },
"@peculiar/asn1-schema": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.3.6.tgz",
@@ -8505,6 +8636,11 @@
"resolved": "https://registry.npmjs.org/jiti/-/jiti-1.18.2.tgz",
"integrity": "sha512-QAdOptna2NYiSSpv0O/BwoHBSmz4YhpzJHyi+fnMRTXFjp7B8i/YG5Z8IfusxB1ufjcD2Sre1F3R+nX3fvy7gg=="
},
+ "jose": {
+ "version": "4.14.4",
+ "resolved": "https://registry.npmjs.org/jose/-/jose-4.14.4.tgz",
+ "integrity": "sha512-j8GhLiKmUAh+dsFXlX1aJCbt5KMibuKb+d7j1JaOJG6s2UjX1PQlW+OKB/sD4a/5ZYF4RcmYmLSndOoU3Lt/3g=="
+ },
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -8620,7 +8756,6 @@
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
- "dev": true,
"requires": {
"yallist": "^4.0.0"
}
@@ -8757,6 +8892,22 @@
}
}
},
+ "next-auth": {
+ "version": "4.22.1",
+ "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.22.1.tgz",
+ "integrity": "sha512-NTR3f6W7/AWXKw8GSsgSyQcDW6jkslZLH8AiZa5PQ09w1kR8uHtR9rez/E9gAq/o17+p0JYHE8QjF3RoniiObA==",
+ "requires": {
+ "@babel/runtime": "^7.20.13",
+ "@panva/hkdf": "^1.0.2",
+ "cookie": "^0.5.0",
+ "jose": "^4.11.4",
+ "oauth": "^0.9.15",
+ "openid-client": "^5.4.0",
+ "preact": "^10.6.3",
+ "preact-render-to-string": "^5.1.19",
+ "uuid": "^8.3.2"
+ }
+ },
"next-themes": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.2.1.tgz",
@@ -8811,11 +8962,21 @@
}
}
},
+ "oauth": {
+ "version": "0.9.15",
+ "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz",
+ "integrity": "sha512-a5ERWK1kh38ExDEfoO6qUHJb32rd7aYmPHuyCu3Fta/cnICvYmgd2uhuKXvPD+PXB+gCEYYEaQdIRAjCOwAKNA=="
+ },
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="
},
+ "object-hash": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz",
+ "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw=="
+ },
"object-inspect": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",
@@ -8893,6 +9054,11 @@
"es-abstract": "^1.20.4"
}
},
+ "oidc-token-hash": {
+ "version": "5.0.3",
+ "resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz",
+ "integrity": "sha512-IF4PcGgzAr6XXSff26Sk/+P4KZFJVuHAJZj3wgO3vX2bMdNVp/QXTP3P7CEm9V1IdG8lDLY3HhiqpsE/nOwpPw=="
+ },
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -8922,6 +9088,17 @@
"is-wsl": "^2.2.0"
}
},
+ "openid-client": {
+ "version": "5.4.2",
+ "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.4.2.tgz",
+ "integrity": "sha512-lIhsdPvJ2RneBm3nGBBhQchpe3Uka//xf7WPHTIglery8gnckvW7Bd9IaQzekzXJvWthCMyi/xVEyGW0RFPytw==",
+ "requires": {
+ "jose": "^4.14.1",
+ "lru-cache": "^6.0.0",
+ "object-hash": "^2.2.0",
+ "oidc-token-hash": "^5.0.3"
+ }
+ },
"optionator": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
@@ -9075,6 +9252,19 @@
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
},
+ "preact": {
+ "version": "10.15.1",
+ "resolved": "https://registry.npmjs.org/preact/-/preact-10.15.1.tgz",
+ "integrity": "sha512-qs2ansoQEwzNiV5eAcRT1p1EC/dmEzaATVDJNiB3g2sRDWdA7b7MurXdJjB2+/WQktGWZwxvDrnuRFbWuIr64g=="
+ },
+ "preact-render-to-string": {
+ "version": "5.2.6",
+ "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.6.tgz",
+ "integrity": "sha512-JyhErpYOvBV1hEPwIxc/fHWXPfnEGdRKxc8gFdAZ7XV4tlzyzG847XAyEZqoDnynP88akM4eaHcSOzNcLWFguw==",
+ "requires": {
+ "pretty-format": "^3.8.0"
+ }
+ },
"prelude-ls": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
@@ -9094,6 +9284,11 @@
"dev": true,
"requires": {}
},
+ "pretty-format": {
+ "version": "3.8.0",
+ "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz",
+ "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew=="
+ },
"prisma": {
"version": "4.14.1",
"resolved": "https://registry.npmjs.org/prisma/-/prisma-4.14.1.tgz",
@@ -9803,6 +9998,11 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
+ "uuid": {
+ "version": "8.3.2",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
+ "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
+ },
"webcrypto-core": {
"version": "1.7.7",
"resolved": "https://registry.npmjs.org/webcrypto-core/-/webcrypto-core-1.7.7.tgz",
@@ -9877,8 +10077,7 @@
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
- "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
- "dev": true
+ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"yaml": {
"version": "2.3.1",
diff --git a/package.json b/package.json
index 27b74495..0080bb54 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
},
"dependencies": {
"@clerk/nextjs": "^4.19.0",
+ "@next-auth/prisma-adapter": "^1.0.6",
"@prisma/client": "^4.14.0",
"@radix-ui/react-navigation-menu": "^1.1.3",
"@radix-ui/react-slot": "^1.0.2",
@@ -25,6 +26,7 @@
"clsx": "^1.2.1",
"lucide-react": "^0.224.0",
"next": "^13.4.2",
+ "next-auth": "^4.22.1",
"next-themes": "^0.2.1",
"react": "18.2.0",
"react-dom": "18.2.0",
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index e7d12e22..71c4bfe9 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -2,8 +2,8 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
- provider = "prisma-client-js"
- previewFeatures = ["jsonProtocol"]
+ provider = "prisma-client-js"
+ previewFeatures = ["jsonProtocol"]
}
datasource db {
@@ -12,9 +12,149 @@ datasource db {
relationMode = "prisma"
}
-model Example {
- id String @id @default(cuid())
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+enum Category {
+ USER
+ ADMIN
}
+enum Difficulty {
+ BEGINNER
+ EASY
+ MEDIUM
+ HARD
+ EXTREME
+}
+
+enum Role {
+ USER
+ ADMIN
+}
+
+enum Status {
+ BANNED
+ ACTIVE // can post, comment, vote, etc
+ PENDING // must finish x number of challenges to be active
+}
+
+// Necessary for Next auth
+model Account {
+ id String @id @default(cuid())
+ userId String
+ type String
+ provider String
+ providerAccountId String
+ refresh_token String? // @db.Text
+ access_token String? // @db.Text
+ expires_at Int?
+ token_type String?
+ scope String?
+ id_token String? // @db.Text
+ session_state String?
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+
+ @@unique([provider, providerAccountId])
+ @@index([userId])
+}
+
+model Session {
+ id String @id @default(cuid())
+ sessionToken String @unique
+ userId String
+ expires DateTime
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+
+ @@index([userId])
+}
+
+model User {
+ id String @id @default(cuid())
+ name String?
+ email String? @unique
+ role Role @default(USER)
+ status Status @default(PENDING)
+ emailVerified DateTime?
+ image String?
+ accounts Account[]
+ sessions Session[]
+ Challenge Challenge[]
+ Vote Vote[]
+ Solution Solution[]
+ Comment Comment[]
+ Report Report[]
+}
+
+model VerificationToken {
+ identifier String
+ token String @unique
+ expires DateTime
+
+ @@unique([identifier, token])
+}
+
+model Challenge {
+ id Int @id @default(autoincrement())
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ category Category
+ difficulty Difficulty
+ prompt String
+ upvotes Int
+ user User @relation(fields: [userId], references: [id])
+ userId String
+ Vote Vote[]
+ Solution Solution[]
+ Comment Comment[]
+ Report Report[]
+
+ @@index([userId])
+}
+
+model Vote {
+ id Int @id @default(autoincrement())
+ user User @relation(fields: [userId], references: [id])
+ userId String
+ challenge Challenge @relation(fields: [challengeId], references: [id])
+ challengeId Int
+ solution Solution @relation(fields: [solutionId], references: [id])
+ solutionId Int
+
+ @@index([userId])
+ @@index([challengeId])
+ @@index([solutionId])
+}
+
+model Solution {
+ id Int @id @default(autoincrement())
+ user User @relation(fields: [userId], references: [id])
+ userId String
+ challenge Challenge @relation(fields: [challengeId], references: [id])
+ challengeId Int
+ Vote Vote[]
+
+ @@index([userId])
+ @@index([challengeId])
+}
+
+model Comment {
+ id Int @id @default(autoincrement())
+ user User @relation(fields: [userId], references: [id])
+ userId String
+ challenge Challenge @relation(fields: [challengeId], references: [id])
+ challengeId Int
+ text String
+
+ @@index([userId])
+ @@index([challengeId])
+}
+
+model Report {
+ id Int @id @default(autoincrement())
+ user User @relation(fields: [userId], references: [id])
+ userId String
+ challenge Challenge @relation(fields: [challengeId], references: [id])
+ challengeId Int
+ text String
+
+ @@index([userId])
+ @@index([challengeId])
+}
diff --git a/src/components/navigation.tsx b/src/components/navigation.tsx
index a56ac1aa..69b38ce3 100644
--- a/src/components/navigation.tsx
+++ b/src/components/navigation.tsx
@@ -1,6 +1,5 @@
import { useTheme } from 'next-themes';
-import { UserButton } from '@clerk/nextjs';
import { Bell, Moon, Sun } from 'lucide-react';
import Link from 'next/link';
import { useEffect, useState } from 'react';
@@ -64,8 +63,6 @@ export function Navigation() {
<button type="button">
<Bell className="h-6 w-6" aria-hidden="true" />
</button>
-
- <UserButton afterSignOutUrl="/" />
</div>
</div>
</nav>
diff --git a/src/components/user/username.tsx b/src/components/user/username.tsx
new file mode 100644
index 00000000..9e49406a
--- /dev/null
+++ b/src/components/user/username.tsx
@@ -0,0 +1,34 @@
+import type { InferGetServerSidePropsType } from 'next';
+import type { getServerSideProps } from '~/pages/[username]';
+import { api } from '~/utils/api';
+
+export function UserPage(props: InferGetServerSidePropsType<typeof getServerSideProps>) {
+ const userQuery = api.user.byName.useQuery({ name: props.username });
+ const mutation = api.user.edit.useMutation();
+
+ const { data: user } = userQuery;
+
+ if (!user) return null;
+
+ const handleClick = (id: string) => {
+ mutation.mutate({
+ id,
+ data: {
+ name: 'bautistaaa',
+ },
+ });
+ };
+
+ return (
+ <>
+ <h1>{user.id}</h1>
+ <img src={user.image ?? ''} />
+
+ <p>{user.email}</p>
+
+ <h2 className="text-xl">Raw user:</h2>
+ <pre>{JSON.stringify(user, null, 4)}</pre>
+ <button onClick={() => handleClick(user.id)}>update user name for id: {user.id}</button>
+ </>
+ );
+}
diff --git a/src/env.mjs b/src/env.mjs
index b3b3d52c..f36d8294 100644
--- a/src/env.mjs
+++ b/src/env.mjs
@@ -1,5 +1,5 @@
-import { createEnv } from "@t3-oss/env-nextjs";
-import { z } from "zod";
+import { createEnv } from '@t3-oss/env-nextjs';
+import { z } from 'zod';
export const env = createEnv({
/**
@@ -8,7 +8,9 @@ export const env = createEnv({
*/
server: {
DATABASE_URL: z.string().url(),
- NODE_ENV: z.enum(["development", "test", "production"]),
+ NODE_ENV: z.enum(['development', 'test', 'production']),
+ GITHUB_ID: z.string(),
+ GITHUB_SECRET: z.string(),
},
/**
@@ -27,6 +29,8 @@ export const env = createEnv({
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
+ GITHUB_SECRET: process.env.GITHUB_SECRET,
+ GITHUB_ID: process.env.GITHUB_ID,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
diff --git a/src/middleware.ts b/src/middleware.ts
deleted file mode 100644
index 126a5865..00000000
--- a/src/middleware.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { authMiddleware } from "@clerk/nextjs";
-
-export default authMiddleware();
-
-export const config = {
- matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
-};
diff --git a/src/pages/[username].tsx b/src/pages/[username].tsx
new file mode 100644
index 00000000..5f2812eb
--- /dev/null
+++ b/src/pages/[username].tsx
@@ -0,0 +1,43 @@
+import { createServerSideHelpers } from '@trpc/react-query/server';
+import type { CreateNextContextOptions } from '@trpc/server/adapters/next';
+import type { GetServerSidePropsContext } from 'next';
+import superjson from 'superjson';
+import { appRouter } from '~/server/api/root';
+import { createTRPCContext } from '~/server/api/trpc';
+
+export async function getServerSideProps(context: GetServerSidePropsContext<{ username: string }>) {
+ const ssg = createServerSideHelpers({
+ router: appRouter,
+ ctx: await createTRPCContext({ req: context.req as any, res: context.res as any }),
+ transformer: superjson,
+ });
+
+ const usernameFromQuery = context.query.username as string;
+
+ if (!usernameFromQuery.startsWith('@')) {
+ return {
+ notFound: true,
+ };
+ }
+
+ const [, username] = usernameFromQuery.split('@');
+
+ const user = await ssg.user.byName.fetch({
+ name: username!,
+ });
+
+ if (!user || !username) {
+ return {
+ notFound: true,
+ };
+ }
+
+ return {
+ props: {
+ trpcState: ssg.dehydrate(),
+ username,
+ },
+ };
+}
+
+export { UserPage as default } from '~/components/user/username';
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index b82b733b..3531238f 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -1,9 +1,11 @@
+import { type Session } from 'next-auth';
+
+import { SessionProvider } from 'next-auth/react';
+
import { ThemeProvider } from 'next-themes';
import { Inter } from 'next/font/google';
-import { ClerkProvider } from '@clerk/nextjs';
-
import { type AppType } from 'next/app';
import '~/styles/globals.css';
import { api } from '~/utils/api';
@@ -11,15 +13,18 @@ import { api } from '~/utils/api';
// If loading a variable font, you don't need to specify the font weight
const inter = Inter({ subsets: ['latin'] });
-const MyApp: AppType = ({ Component, pageProps }) => {
+const MyApp: AppType<{ session: Session | null }> = ({
+ Component,
+ pageProps: { session, ...pageProps },
+}) => {
return (
- <ClerkProvider {...pageProps}>
- <ThemeProvider attribute="class">
- <main className={`${inter.className} bg-white dark:bg-neutral-950`}>
+ <ThemeProvider attribute="class">
+ <SessionProvider session={session}>
+ <main className={`${inter.className} bg-white dark:bg-neutral-900`}>
<Component {...pageProps} />
</main>
- </ThemeProvider>
- </ClerkProvider>
+ </SessionProvider>
+ </ThemeProvider>
);
};
diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts
new file mode 100644
index 00000000..9dabfb5a
--- /dev/null
+++ b/src/pages/api/auth/[...nextauth].ts
@@ -0,0 +1,4 @@
+import NextAuth from 'next-auth';
+import { authOptions } from '~/server/auth';
+
+export default NextAuth(authOptions);
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 8b526623..b4113fb4 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,7 +1,10 @@
import { type NextPage } from 'next';
+import { signIn, signOut, useSession } from 'next-auth/react';
+
import Head from 'next/head';
import { TypographyH1 } from '~/components/h1';
import { Navigation } from '~/components/navigation';
+import { api } from '~/utils/api';
const Home: NextPage = () => {
return (
@@ -18,8 +21,35 @@ const Home: NextPage = () => {
<header>
<TypographyH1>TypeHero</TypographyH1>
</header>
+ <main>
+ <AuthShowcase />
+ </main>
</>
);
};
export default Home;
+
+const AuthShowcase: React.FC = () => {
+ const { data: sessionData } = useSession();
+
+ const { data: secretMessage } = api.example.getSecretMessage.useQuery(
+ undefined, // no input
+ { enabled: sessionData?.user !== undefined },
+ );
+
+ return (
+ <div className="flex flex-col items-center justify-center gap-4">
+ <p className="text-center text-2xl text-white">
+ {sessionData && <span>Logged in as {sessionData.user?.name}</span>}
+ {secretMessage && <span> - {secretMessage}</span>}
+ </p>
+ <button
+ className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
+ onClick={sessionData ? () => void signOut() : () => void signIn()}
+ >
+ {sessionData ? 'Sign out' : 'Sign in'}
+ </button>
+ </div>
+ );
+};
diff --git a/src/pages/pages/[id].tsx b/src/pages/pages/[id].tsx
new file mode 100644
index 00000000..e69de29b
diff --git a/src/pages/sign-in/[[...index]].tsx b/src/pages/sign-in/[[...index]].tsx
deleted file mode 100644
index 2cc13d4c..00000000
--- a/src/pages/sign-in/[[...index]].tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { SignIn } from "@clerk/nextjs";
-
-export default function Page() {
- return <SignIn />;
-}
diff --git a/src/pages/sign-up/[[...index]].tsx b/src/pages/sign-up/[[...index]].tsx
deleted file mode 100644
index 27439454..00000000
--- a/src/pages/sign-up/[[...index]].tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { SignUp } from "@clerk/nextjs";
-
-export default function Page() {
- return <SignUp />;
-}
diff --git a/src/server/api/root.ts b/src/server/api/root.ts
index 7caea0fe..e8586077 100644
--- a/src/server/api/root.ts
+++ b/src/server/api/root.ts
@@ -1,5 +1,6 @@
-import { exampleRouter } from "~/server/api/routers/example";
-import { createTRPCRouter } from "~/server/api/trpc";
+import { exampleRouter } from '~/server/api/routers/example';
+import { createTRPCRouter } from '~/server/api/trpc';
+import { userRouter } from './routers/user';
/**
* This is the primary router for your server.
@@ -8,6 +9,7 @@ import { createTRPCRouter } from "~/server/api/trpc";
*/
export const appRouter = createTRPCRouter({
example: exampleRouter,
+ user: userRouter,
});
// export type definition of API
diff --git a/src/server/api/routers/example.ts b/src/server/api/routers/example.ts
index 8aff6410..3471999b 100644
--- a/src/server/api/routers/example.ts
+++ b/src/server/api/routers/example.ts
@@ -1,24 +1,18 @@
-import { z } from "zod";
-import {
- createTRPCRouter,
- protectedProcedure,
- publicProcedure,
-} from "~/server/api/trpc";
+import { z } from 'zod';
+import { createTRPCRouter, protectedProcedure, publicProcedure } from '~/server/api/trpc';
export const exampleRouter = createTRPCRouter({
- hello: publicProcedure
- .input(z.object({ text: z.string() }))
- .query(({ input }) => {
- return {
- greeting: `Hello ${input.text}`,
- };
- }),
+ hello: publicProcedure.input(z.object({ text: z.string() })).query(({ input }) => {
+ return {
+ greeting: `Hello ${input.text}`,
+ };
+ }),
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.example.findMany();
}),
getSecretMessage: protectedProcedure.query(() => {
- return "you can now see this secret message!";
+ return 'you can now see this secret message!';
}),
});
diff --git a/src/server/api/routers/user.ts b/src/server/api/routers/user.ts
new file mode 100644
index 00000000..fe4145e8
--- /dev/null
+++ b/src/server/api/routers/user.ts
@@ -0,0 +1,68 @@
+import { z } from 'zod';
+import { createTRPCRouter, protectedProcedure, publicProcedure } from '~/server/api/trpc';
+
+export const userRouter = createTRPCRouter({
+ all: publicProcedure.query(({ ctx }) => {
+ return ctx.prisma.user.findMany();
+ }),
+ byId: publicProcedure
+ .input(
+ z.object({
+ id: z.string(),
+ }),
+ )
+ .query(({ ctx, input }) => {
+ const { id } = input;
+ return ctx.prisma.user.findUnique({
+ where: { id },
+ });
+ }),
+ byName: publicProcedure
+ .input(
+ z.object({
+ name: z.string(),
+ }),
+ )
+ .query(({ ctx, input }) => {
+ const { name } = input;
+ return ctx.prisma.user.findFirst({
+ where: {
+ name: {
+ equals: name,
+ },
+ },
+ });
+ }),
+ edit: protectedProcedure
+ .input(
+ z.object({
+ id: z.string(),
+ data: z.object({
+ // email: z.string().min(1).max(32).optional(),
+ name: z.string().min(1).optional(),
+ // image: z.string().min(1).optional(),
+ }),
+ }),
+ )
+ .mutation(async ({ ctx, input }) => {
+ const { id, data } = input;
+ const post = await ctx.prisma.user.update({
+ where: { id },
+ data,
+ });
+ return post;
+ }),
+ delete: protectedProcedure
+ .input(
+ z.object({
+ id: z.string(),
+ }),
+ )
+ .mutation(async ({ ctx, input }) => {
+ const { id } = input;
+ await ctx.prisma.user.delete({ where: { id } });
+ return {
+ id,
+ };
+ }),
+});
diff --git a/src/server/api/trpc.ts b/src/server/api/trpc.ts
index 0a7fa2f4..680e7919 100644
--- a/src/server/api/trpc.ts
+++ b/src/server/api/trpc.ts
@@ -7,6 +7,14 @@
* need to use are documented accordingly near the end.
*/
+import { initTRPC, TRPCError } from '@trpc/server';
+import { type CreateNextContextOptions } from '@trpc/server/adapters/next';
+import { type Session } from 'next-auth';
+import superjson from 'superjson';
+import { ZodError } from 'zod';
+import { getServerAuthSession } from '~/server/auth';
+import { prisma } from '~/server/db';
+
/**
* 1. CONTEXT
*
@@ -14,9 +22,6 @@
*
* These allow you to access things when processing a request, like the database, the session, etc.
*/
-import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
-
-import { prisma } from "~/server/db";
/**
* This is the actual context you will use in your router. It will be used to process every request
@@ -24,27 +29,25 @@ import { prisma } from "~/server/db";
*
* @see https://trpc.io/docs/context
*/
-export const createTRPCContext = (opts: CreateNextContextOptions) => {
- const { req } = opts;
- const sesh = getAuth(req);
+export const createTRPCContext = async (opts: CreateNextContextOptions) => {
+ const { req, res } = opts;
- const userId = sesh.userId;
+ // Get the session from the server using the getServerSession wrapper function
+ const session = await getServerAuthSession({ req, res });
return {
+ session,
prisma,
- userId,
};
};
/**
* 2. INITIALIZATION
*
- * This is where the tRPC API is initialized, connecting the context and transformer.
+ * This is where the tRPC API is initialized, connecting the context and transformer. We also parse
+ * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
+ * errors on the backend.
*/
-import { getAuth } from "@clerk/nextjs/server";
-import { initTRPC, TRPCError } from "@trpc/server";
-import superjson from "superjson";
-import { ZodError } from "zod";
const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
@@ -53,8 +56,7 @@ const t = initTRPC.context<typeof createTRPCContext>().create({
...shape,
data: {
...shape.data,
- zodError:
- error.cause instanceof ZodError ? error.cause.flatten() : null,
+ zodError: error.cause instanceof ZodError ? error.cause.flatten() : null,
},
};
},
@@ -83,18 +85,25 @@ export const createTRPCRouter = t.router;
*/
export const publicProcedure = t.procedure;
-const enforceUserIsAuthed = t.middleware(async ({ ctx, next }) => {
- if (!ctx.userId) {
- throw new TRPCError({
- code: "UNAUTHORIZED",
- });
+/** Reusable middleware that enforces users are logged in before running the procedure. */
+const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
+ if (!ctx.session || !ctx.session.user) {
+ throw new TRPCError({ code: 'UNAUTHORIZED' });
}
-
return next({
ctx: {
- userId: ctx.userId,
+ // infers the `session` as non-nullable
+ session: { ...ctx.session, user: ctx.session.user },
},
});
});
+/**
+ * Protected (authenticated) procedure
+ *
+ * If you want a query or mutation to ONLY be accessible to logged in users, use this. It verifies
+ * the session is valid and guarantees `ctx.session.user` is not null.
+ *
+ * @see https://trpc.io/docs/procedures
+ */
export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
diff --git a/src/server/auth.ts b/src/server/auth.ts
new file mode 100644
index 00000000..66ddcbc2
--- /dev/null
+++ b/src/server/auth.ts
@@ -0,0 +1,73 @@
+import { PrismaAdapter } from '@next-auth/prisma-adapter';
+import { type GetServerSidePropsContext } from 'next';
+import { getServerSession, type NextAuthOptions, type DefaultSession } from 'next-auth';
+import GitHubProvider from 'next-auth/providers/github';
+import { env } from '~/env.mjs';
+import { prisma } from '~/server/db';
+
+/**
+ * Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
+ * object and keep type safety.
+ *
+ * @see https://next-auth.js.org/getting-started/typescript#module-augmentation
+ */
+declare module 'next-auth' {
+ interface Session extends DefaultSession {
+ user: {
+ id: string;
+ // ...other properties
+ // role: UserRole;
+ } & DefaultSession['user'];
+ }
+
+ // interface User {
+ // // ...other properties
+ // // role: UserRole;
+ // }
+}
+
+/**
+ * Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
+ *
+ * @see https://next-auth.js.org/configuration/options
+ */
+export const authOptions: NextAuthOptions = {
+ callbacks: {
+ session: ({ session, user }) => ({
+ ...session,
+ user: {
+ ...session.user,
+ id: user.id,
+ },
+ }),
+ },
+ adapter: PrismaAdapter(prisma),
+ providers: [
+ GitHubProvider({
+ clientId: env.GITHUB_ID,
+ clientSecret: env.GITHUB_SECRET,
+ }),
+
+ /**
+ * ...add more providers here.
+ *
+ * Most other providers require a bit more work than the Discord provider. For example, the
+ * GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
+ * model. Refer to the NextAuth.js docs for the provider you want to use. Example:
+ *
+ * @see https://next-auth.js.org/providers/github
+ */
+ ],
+};
+
+/**
+ * Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
+ *
+ * @see https://next-auth.js.org/configuration/nextjs
+ */
+export const getServerAuthSession = (ctx: {
+ req: GetServerSidePropsContext['req'];
+ res: GetServerSidePropsContext['res'];
+}) => {
+ return getServerSession(ctx.req, ctx.res, authOptions);
+};
diff --git a/src/server/db.ts b/src/server/db.ts
index 87ece8b7..eb35e9da 100644
--- a/src/server/db.ts
+++ b/src/server/db.ts
@@ -1,5 +1,5 @@
-import { PrismaClient } from "@prisma/client";
-import { env } from "~/env.mjs";
+import { PrismaClient } from '@prisma/client';
+import { env } from '~/env.mjs';
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
@@ -8,8 +8,7 @@ const globalForPrisma = globalThis as unknown as {
export const prisma =
globalForPrisma.prisma ??
new PrismaClient({
- log:
- env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
+ log: env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
});
-if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
+if (env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
diff --git a/src/utils/redirectIf.ts b/src/utils/redirectIf.ts
new file mode 100644
index 00000000..8bffc09a
--- /dev/null
+++ b/src/utils/redirectIf.ts
@@ -0,0 +1,57 @@
+import type { GetServerSidePropsContext } from 'next';
+import { getSession } from 'next-auth/react';
+
+interface RedirectIfOptions {
+ unauthenticated?: boolean;
+ is?: UserType;
+ not?: UserType;
+}
+
+export const redirectIf =
+ (conditions: RedirectIfOptions, redirect: string = '/home') =>
+ async (ctx: GetServerSidePropsContext) => {
+ const session = await getSession(ctx);
+
+ if (conditions.unauthenticated) {
+ // if (fullSession) {
+ // return {
+ // redirect: {
+ // destination: redirect,
+ // permanent: false,
+ // },
+ // };
+ // }
+ } else if (!fullSession) {
+ // return {
+ // redirect: {
+ // destination: `/auth/signin?redirect=${encodeURIComponent(ctx.resolvedUrl)}`,
+ // permanent: false,
+ // },
+ // };
+ }
+
+ if (
+ (conditions.is && session?.user?.type === conditions.is) ||
+ (conditions.not && session?.user.type !== conditions.not)
+ ) {
+ return {
+ redirect: {
+ destination: redirect,
+ permanent: false,
+ },
+ };
+ }
+
+ return {
+ props: {},
+ };
+ };
+
+export const authenticatedRoute = redirectIf({});
+export const unauthenticatedRoute = redirectIf({ unauthenticated: true });
+
+export const creatorRoute = redirectIf({ not: UserType.CREATOR }, '/creator/apply');
+
+export const creatorPendingRoute = redirectIf({ not: UserType.CREATOR_PENDING }, '/creator');
+
+export const nonCreatorRoute = redirectIf({ is: UserType.CREATOR }, '/creator');
diff --git a/truncate.js b/truncate.js
new file mode 100644
index 00000000..72b74752
--- /dev/null
+++ b/truncate.js
@@ -0,0 +1,27 @@
+const { PrismaClient } = require('@prisma/client');
+
+const prisma = new PrismaClient();
+
+async function truncateTables() {
+ try {
+ // Get all table names
+ const tableNames = await prisma.$queryRaw`
+ SELECT table_name FROM information_schema.tables
+ WHERE table_schema = 'public' -- Replace 'public' with your schema name if necessary
+ AND table_type = 'BASE TABLE'
+ `;
+
+ // Truncate each table
+ for (const { table_name } of tableNames) {
+ await prisma.$queryRaw`TRUNCATE TABLE "${table_name}" RESTART IDENTITY CASCADE`;
+ }
+
+ console.log('All tables truncated successfully.');
+ } catch (error) {
+ console.error('Error truncating tables:', error);
+ } finally {
+ await prisma.$disconnect();
+ }
+}
+
+truncateTables();