Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement dev bypass #730

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 1 addition & 5 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch
const checkValidatorAvailability = async () => {
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_VALIDATOR}/health`);
if (response.ok) {
return true;
} else {
return false;
}
return response.ok;
} catch (error) {
return false;
}
Expand Down
49,736 changes: 24,499 additions & 25,237 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
},
"dependencies": {
"@dnd-kit/core": "^6.0.6",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.3.1",
"@mui/lab": "^5.0.0-alpha.67",
"@mui/material": "^5.4.0",
"@next-auth/prisma-adapter": "^1.0.5",
"@next/bundle-analyzer": "^13.1.6",
"@prisma/client": "^5.0.0",
"@radix-ui/react-checkbox": "^1.0.1",
"@radix-ui/react-dialog": "^1.0.3",
"@radix-ui/react-dialog": "1.0.3",
"@radix-ui/react-dropdown-menu": "2.0.2",
"@radix-ui/react-hover-card": "1.0.4",
"@radix-ui/react-select": "1.2.1",
Expand All @@ -47,6 +48,7 @@
"@vercel/analytics": "^0.1.11",
"async-mutex": "^0.4.0",
"axios": "^1.3.4",
"cookies": "^0.8.0",
"eslint": "^8.8.0",
"eslint-plugin-unused-imports": "^2.0.0",
"framer-motion": "^6.2.3",
Expand All @@ -72,11 +74,29 @@
"devDependencies": {
"@babel/core": "^7.20.12",
"@jest/globals": "^29.6.1",
"@types/babel__generator": "^7.6.7",
"@types/babel__template": "^7.4.4",
"@types/body-parser": "^1.19.5",
"@types/connect": "^3.4.38",
"@types/cookies": "^0.7.9",
"@types/eslint": "^8.44.7",
"@types/express": "^4.17.21",
"@types/http-errors": "^2.0.4",
"@types/istanbul-lib-report": "^3.0.3",
"@types/keygrip": "^1.0.5",
"@types/mime": "^3.0.4",
"@types/minimatch": "^5.1.2",
"@types/node": "^17.0.14",
"@types/nprogress": "^0.2.0",
"@types/prop-types": "^15.7.10",
"@types/qs": "^6.9.10",
"@types/range-parser": "^1.2.7",
"@types/react": "^17.0.39",
"@types/react-dom": "^18.0.11",
"@types/scheduler": "^0.16.6",
"@types/send": "^0.17.4",
"@types/uuid": "^9.0.2",
"@types/yargs-parser": "^21.0.3",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"autoprefixer": "^10.4.2",
"cross-env": "^7.0.3",
Expand Down
38 changes: 29 additions & 9 deletions prisma/seedTestUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ export interface SeededUserData {
}

export const seedTestUser = async (prisma: PrismaClient): Promise<SeededUserData> => {
const uuid = '00000000-0000-0000-0000-000000000000';
// Create user
const user = await prisma.user.create({
data: {
const user = await prisma.user.upsert({
where: {
email: '[email protected]',
},
update: {
id: uuid,
},
create: {
id: uuid,
email: '[email protected]',
onboardingComplete: true,
seenHomeOnboardingModal: true,
Expand All @@ -23,8 +31,15 @@ export const seedTestUser = async (prisma: PrismaClient): Promise<SeededUserData
// Create profile
const [profile, account, session] = await Promise.all([
// Create profile
prisma.profile.create({
data: {
prisma.profile.upsert({
where: {
userId: user.id,
},
update: {
id: uuid,
},
create: {
id: uuid,
name: 'Test User',
startYear: 2021,
startSemester: 's',
Expand All @@ -34,11 +49,16 @@ export const seedTestUser = async (prisma: PrismaClient): Promise<SeededUserData
},
}),
// Create account
prisma.account.create({
data: {
type: 'test',
provider: 'test',
providerAccountId: 'test123',
prisma.account.upsert({
where: {
id: uuid,
},
update: {},
create: {
id: uuid,
type: 'test_bypass',
provider: 'test_bypass',
providerAccountId: 'test123_bypass',
userId: user.id,
},
}),
Expand Down
11 changes: 10 additions & 1 deletion src/components/planner/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ const Toolbar: FC<ToolbarProps> = ({
),
});

useEffect(() => update(), [update, studentName, title, semesters, transferCredits, coursesData]);
useEffect(() => update(
<DegreePlanPDF
studentName={studentName}
planTitle={title}
major={major}
semesters={semesters}
transferCredits={transferCredits}
coursesData={coursesData ?? []}
/>
), [update, studentName, title, semesters, transferCredits, coursesData]);
return (
<div className="flex flex-row items-start gap-2 py-1 text-primary-900">
<ToolbarWrapper>
Expand Down
1 change: 1 addition & 0 deletions src/env/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const serverSchema = z.object({
DIRECT_DATABASE_URL: z.string().url(),
PLATFORM_DATABASE_URL: z.string().url(),
NODE_ENV: z.enum(['development', 'test', 'production']),
VERCEL_ENV: z.enum(['development', 'preview', 'production']),
NEXTAUTH_SECRET:
process.env.NODE_ENV === 'production' ? z.string().min(1) : z.string().min(1).optional(),
NEXTAUTH_URL: z.preprocess(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ export const authOptions: NextAuthOptions = {
},
from: env.EMAIL_FROM,
}),
// ...add more providers here
],
pages: {
signIn: '/auth/login',
signOut: '/',
newUser: '/app/onboarding',
},
};

export default NextAuth(authOptions);
29 changes: 27 additions & 2 deletions src/pages/app/home.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
import { createServerSideHelpers } from '@trpc/react-query/server';
import Cookies from 'cookies';
import { GetServerSidePropsContext } from 'next';
import { getServerSession } from 'next-auth';
import superjson from 'superjson';

import { env } from '@/env/server.mjs';
import { appRouter } from '@/server/trpc/router/_app';
import { createContextInner } from '@server/trpc/context';
import { seedTestUser } from 'prisma/seedTestUser';

import Home from '../../components/home/Home';
import { prisma } from '../../server/db/client';
import { authOptions } from '../api/auth/[...nextauth]';

export async function getServerSideProps(context: GetServerSidePropsContext) {
const session = await getServerSession(context.req, context.res, authOptions);
let serverSession = await getServerSession(context.req, context.res, authOptions);
if (!serverSession && env.VERCEL_ENV === 'preview' || env.VERCEL_ENV === 'development' || env.NODE_ENV === 'development') {
// bypass login using test user for convenience
const { user, session } = await seedTestUser(prisma);
serverSession = {
user: {
id: session.userId,
email: user.email,
},
expires: new Date(session.expires).toISOString(),
};
const cookies = new Cookies(context.req, context.res);
cookies.set('next-auth.session-token', session.sessionToken, {
domain: 'localhost',
// session is not actually a 'Date' object here, it's a string
expires: new Date(session.expires),
httpOnly: true,
path: '/',
secure: false,
});
}
const ssg = createServerSideHelpers({
router: appRouter,
ctx: await createContextInner({ session }),
ctx: await createContextInner({ session: serverSession }),
transformer: superjson,
});

Expand Down
6 changes: 3 additions & 3 deletions src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const EMAIL_VALIDATION_ERROR_TIMEOUT_MS = 600;
*/
export default function LoginPage({
providers,
}: InferGetServerSidePropsType<typeof getStaticProps>): JSX.Element {
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element {
return <AuthPage providers={providers} />;
}

Expand Down Expand Up @@ -73,7 +73,7 @@ export function AuthPage(props: {
setEmail(event.target.value);
};

const handleEmailSignIn = () => {
const handleEmailSignIn = async () => {
if (isEmailValid) {
setIsModifyLoading(true);
signIn('email', {
Expand Down Expand Up @@ -178,7 +178,7 @@ export function AuthPage(props: {
</div>
);
}
export async function getStaticProps() {
export async function getServerSideProps() {
const providers = await getProviders();

if (providers && providers['email']) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/auth/signup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { InferGetServerSidePropsType } from 'next';

import { AuthPage, getStaticProps } from './login';
import { AuthPage, getServerSideProps } from './login';

export default function LoginPage({
providers,
}: InferGetServerSidePropsType<typeof getStaticProps>): JSX.Element {
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element {
return <AuthPage providers={providers} signUp />;
}

export { getStaticProps } from './login';
export { getServerSideProps } from './login';
7 changes: 1 addition & 6 deletions validator/degree_data/2022/Psychology(BS).json
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,7 @@
"metadata": {
"id": "Psychology(BS)-29"
},
"accepted_prefixes": [
"PSY",
"CGS",
"CLDP",
"NSC"
]
"accepted_prefixes": ["PSY", "CGS", "CLDP", "NSC"]
}
]
},
Expand Down
Loading