Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
REPOSITORY: ${{ vars.REPOSITORY }}
run: |
rm -f /tmp/migration.zip
if [ -f "prisma/schema.prisma" ]; then
if [ -f "prisma/schema.prisma" ] || [ -d "prisma/schema" ] || [ -f "prisma.config.ts" ]; then
echo "ORM=prisma" >> $GITHUB_ENV
FILES="package.json pnpm-lock.yaml tsconfig.json prisma/"
[ -f pnpm-workspace.yaml ] && FILES="$FILES pnpm-workspace.yaml"
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
--invocation-type RequestResponse \
--cli-read-timeout 900 \
--cli-binary-format raw-in-base64-out \
--payload '{"project":"${{ vars.REPOSITORY }}","environment":"prod","orm":"${{ env.ORM }}","migration_bucket":"npts-env-bucket","migration_key":"${{ vars.REPOSITORY }}/migrations/${{ github.sha }}.zip"}' \
--payload '{"project":"${{ vars.REPOSITORY }}","environment":"prod","orm":"${{ env.ORM }}","migration_bucket":"npts-env-bucket","migration_key":"${{ vars.REPOSITORY }}/migrations/${{ github.sha }}.zip","seed":${{ vars.SEED_MIGRATION == 'true' }}}' \
/tmp/lambda-response.json

STATUS=$(jq -r '.status' /tmp/lambda-response.json)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
REPOSITORY: ${{ vars.REPOSITORY }}
run: |
rm -f /tmp/migration.zip
if [ -f "prisma/schema.prisma" ]; then
if [ -f "prisma/schema.prisma" ] || [ -d "prisma/schema" ] || [ -f "prisma.config.ts" ]; then
echo "ORM=prisma" >> $GITHUB_ENV
FILES="package.json pnpm-lock.yaml tsconfig.json prisma/"
[ -f pnpm-workspace.yaml ] && FILES="$FILES pnpm-workspace.yaml"
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
--invocation-type RequestResponse \
--cli-read-timeout 900 \
--cli-binary-format raw-in-base64-out \
--payload '{"project":"${{ vars.REPOSITORY }}","environment":"stage","orm":"${{ env.ORM }}","migration_bucket":"npts-env-bucket","migration_key":"${{ vars.REPOSITORY }}/migrations/${{ github.sha }}.zip"}' \
--payload '{"project":"${{ vars.REPOSITORY }}","environment":"stage","orm":"${{ env.ORM }}","migration_bucket":"npts-env-bucket","migration_key":"${{ vars.REPOSITORY }}/migrations/${{ github.sha }}.zip","seed":${{ vars.SEED_MIGRATION == 'true' }}}' \
/tmp/lambda-response.json

STATUS=$(jq -r '.status' /tmp/lambda-response.json)
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ logs
!.env.example

*.db
prisma/client
prisma/generated/
4 changes: 1 addition & 3 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

<script setup lang="ts">

import { authClient } from "~~/lib/auth-client";

const route = useRoute();
const { data: session } = await authClient.useSession(useFetch);
const { data: session } = await useAuthSession();
const loggedIn = computed(() => !!session.value);
const userRole = computed(() => session.value?.user?.role);

Expand Down
12 changes: 12 additions & 0 deletions composables/useAuthSession.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useFetch } from "#app";
import { authClient } from "~~/lib/auth-client";

export function useAuthSession() {
const relativeFetch = ((url: string, opts?: any) => {
try {
if (url.startsWith("http")) url = new URL(url).pathname;
} catch {}
return useFetch(url, opts);
}) as any;
return authClient.useSession(relativeFetch);
}
35 changes: 21 additions & 14 deletions lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { PrismaClient } from "@/prisma/client/client";
import path from "node:path";

const dbPath = process.env.DATABASE_URL?.startsWith("file:")
? `file:${path.resolve(process.cwd(), "prisma/dev.db")}`
: process.env.DATABASE_URL;

export const prisma = new PrismaClient({
datasources: {
db: {
url: dbPath,
},
},
});
import { PrismaClient } from "@/prisma/generated/client";
import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";

const prismaClientSingleton = () => {
const adapter = new PrismaBetterSqlite3({
url: process.env.DATABASE_URL,
});
return new PrismaClient({ adapter });
};

declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();

export default prisma;

export { prisma };

if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
"postinstall": "nuxt prepare",
"db:generate": "prisma generate"
},
"devDependencies": {
"@prisma/client": "^6.6.0",
"@types/nodemailer": "^8.0.1",
"prisma": "^6.6.0",
"prisma": "7.3.0",
"tsx": "^4.23.1"
},
"description": "March to the Polls - Student Voter Registration Portal",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@better-auth/prisma-adapter": "^1.6.25",
"@prisma/adapter-better-sqlite3": "^7.3.0",
"@prisma/client": "7.3.0",
"@tailwindcss/vite": "^4.3.3",
"better-auth": "^1.6.25",
"dotenv": "^17.2.3",
"nodemailer": "^9.0.3",
"nuxt": "4.5.0",
"nuxt": "4.5.2",
"papaparse": "^5.5.2",
"tailwindcss": "^4.3.3",
"xlsx": "^0.18.5"
},
"prisma": {
"seed": "pnpm tsx prisma/seed.ts"
},
"keywords": [],
"author": "",
"license": "ISC"
Expand Down
7 changes: 4 additions & 3 deletions pages/admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ user.value.role = null;

const isRemovalSuccessful = ref(false);
const successMessage = ref('');
const isError = ref(false);
const errorMessage = ref('');
const isLoading = ref(false);

users.value = await getUsers()

Expand Down Expand Up @@ -288,9 +291,7 @@ let addedUser = null
users.value = await getUsers()
}

import { authClient } from "~~/lib/auth-client";

const { data: session } = await authClient.useSession(useFetch);
const { data: session } = await useAuthSession();

// Nuxt router guards - if session.user.role is in list of allowed roles, allow else redirect to index
// we can also hide navbar elements in app.vue depending on role so that
Expand Down
4 changes: 1 addition & 3 deletions pages/database.vue
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,7 @@ const removeStudent = async (id) => {



import { authClient } from "~~/lib/auth-client";

const { data: session } = await authClient.useSession(useFetch);
const { data: session } = await useAuthSession();
const userRole = computed(() => session.value?.user?.role);
const currid = computed(() => session.value?.user?.id);

Expand Down
4 changes: 1 addition & 3 deletions pages/editStudent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@
</style>

<script setup>
import { authClient } from "~~/lib/auth-client";

const { data: session } = await authClient.useSession(useFetch);
const { data: session } = await useAuthSession();
const userRole = computed(() => session.value?.user?.role);
const students = ref(null)
var student = ref({
Expand Down
4 changes: 1 addition & 3 deletions pages/entry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@
import Error from "~/components/Error.vue";
import Notification from "~/components/Notification.vue";

import { authClient } from "~~/lib/auth-client";

const { data: session } = await authClient.useSession(useFetch);
const { data: session } = await useAuthSession();
const userRole = computed(() => session.value?.user?.role);
const students = ref(null)
const student = ref({
Expand Down
4 changes: 1 addition & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
</template>

<script setup>
import { authClient } from "~~/lib/auth-client";

const { data: session } = await authClient.useSession(useFetch);
const { data: session } = await useAuthSession();
const name = computed(() => session.value?.user?.firstName ?? "");
</script>
Loading
Loading