Skip to content

Commit

Permalink
Update auth to use NextAuth.js v5 beta (Auth,js)
Browse files Browse the repository at this point in the history
  • Loading branch information
salimi-my committed Jan 30, 2024
1 parent ca64858 commit 7abd901
Show file tree
Hide file tree
Showing 44 changed files with 3,558 additions and 2,803 deletions.
9 changes: 2 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# App URL
APP_URL=http://localhost:3000

# Resend configurations
RESEND_API_KEY=AddResendAPIKey

# NextAuth configurations
NEXTAUTH_URL=AddDefaultURL
NEXTAUTH_SECRET=AddSecret
NEXTAUTH_JWT_SECRET=AddJWTSecret
AUTH_URL=http://localhost:3000
AUTH_SECRET=npx auth secret or pnpm dlx auth secret

# Prisma configurations
DATABASE_URL="AddMySQLURL"
Expand Down
10 changes: 5 additions & 5 deletions app/(secured)/admin/(routes)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import AboutForm from '@/components/secured/about-form';
import {
Card,
Expand All @@ -12,15 +12,15 @@ import {
} from '@/components/ui/card';

export default async function AboutPage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const about = await prismadb.about.findFirst({
where: {
userId: session?.user?.id
userId: user.id
}
});

Expand Down
14 changes: 7 additions & 7 deletions app/(secured)/admin/(routes)/account/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import AccountForm from '@/components/secured/account-form';
import {
Card,
Expand All @@ -12,15 +12,15 @@ import {
} from '@/components/ui/card';

export default async function AccountPage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const user = await prismadb.user.findUnique({
const loggedInUser = await prismadb.user.findUnique({
where: {
id: session?.user?.id
id: user.id
},
select: {
name: true,
Expand All @@ -37,7 +37,7 @@ export default async function AccountPage() {
</CardDescription>
</CardHeader>
<CardContent>
<AccountForm user={user} />
<AccountForm user={loggedInUser} />
</CardContent>
</Card>
);
Expand Down
12 changes: 6 additions & 6 deletions app/(secured)/admin/(routes)/experience/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import ExperienceForm from '@/components/secured/experience-form';
import {
Card,
Expand All @@ -12,22 +12,22 @@ import {
} from '@/components/ui/card';

export default async function ExperiencePage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const frontendItems = await prismadb.experience.findMany({
where: {
userId: session?.user?.id,
userId: user.id,
type: 'FRONTEND'
}
});

const backendItems = await prismadb.experience.findMany({
where: {
userId: session?.user?.id,
userId: user.id,
type: 'BACKEND'
}
});
Expand Down
14 changes: 7 additions & 7 deletions app/(secured)/admin/(routes)/expertise/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import ExpertiseForm from '@/components/secured/expertise-form';
import {
Card,
Expand All @@ -12,29 +12,29 @@ import {
} from '@/components/ui/card';

export default async function ExpertisePage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const seoOptimizationItems = await prismadb.expertise.findMany({
where: {
userId: session?.user?.id,
userId: user.id,
type: 'SEOOPTIMIZATION'
}
});

const webDevelopmentItems = await prismadb.expertise.findMany({
where: {
userId: session?.user?.id,
userId: user.id,
type: 'WEBDEVELOPMENT'
}
});

const contentCreationItems = await prismadb.expertise.findMany({
where: {
userId: session?.user?.id,
userId: user.id,
type: 'CONTENTCREATION'
}
});
Expand Down
10 changes: 5 additions & 5 deletions app/(secured)/admin/(routes)/miscellaneous/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import MiscellaneousForm from '@/components/secured/miscellaneous-form';
import {
Card,
Expand All @@ -12,15 +12,15 @@ import {
} from '@/components/ui/card';

export default async function MiscellaneousPage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const miscellaneous = await prismadb.miscellaneous.findFirst({
where: {
userId: session?.user?.id
userId: user.id
},
include: {
titles: true
Expand Down
22 changes: 11 additions & 11 deletions app/(secured)/admin/(routes)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Link from 'next/link';
import { redirect } from 'next/navigation';
import { Book, Briefcase, FolderGit2, Laptop } from 'lucide-react';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { Button } from '@/components/ui/button';
import { currentUser } from '@/lib/authentication';
import MiniCard from '@/components/secured/mini-card';
import RecentProject from '@/components/secured/recent-project';
import QualificationTab from '@/components/secured/qualification-tab';
Expand All @@ -17,10 +17,10 @@ import {
} from '@/components/ui/card';

export default async function DashboardPage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const [
Expand All @@ -33,15 +33,15 @@ export default async function DashboardPage() {
] = await prismadb.$transaction([
prismadb.portfolio.count({
where: {
userId: session.user.id
userId: user.id
}
}),
prismadb.qualification.findFirst({
select: {
startYear: true
},
where: {
userId: session.user.id,
userId: user.id,
type: 'EXPERIENCE'
},
orderBy: {
Expand All @@ -50,14 +50,14 @@ export default async function DashboardPage() {
}),
prismadb.qualification.findFirst({
where: {
userId: session.user.id,
userId: user.id,
type: 'EXPERIENCE',
endYear: 'Present'
}
}),
prismadb.qualification.findMany({
where: {
userId: session.user.id,
userId: user.id,
type: 'EDUCATION'
},
orderBy: {
Expand All @@ -66,7 +66,7 @@ export default async function DashboardPage() {
}),
prismadb.qualification.findMany({
where: {
userId: session.user.id,
userId: user.id,
type: 'EXPERIENCE'
},
orderBy: {
Expand All @@ -76,7 +76,7 @@ export default async function DashboardPage() {
prismadb.portfolio.findMany({
take: 5,
where: {
userId: session.user.id
userId: user.id
},
orderBy: {
createdAt: 'desc'
Expand All @@ -93,7 +93,7 @@ export default async function DashboardPage() {
<>
<div className='flex items-center justify-between mb-4'>
<h2 className='text-2xl md:text-3xl font-bold tracking-tight'>
Welcome {session.user.name}
Welcome {user.name}
</h2>
<div className='flex items-center'>
<Button size='sm' asChild>
Expand Down
10 changes: 5 additions & 5 deletions app/(secured)/admin/(routes)/portfolio/[portfolioId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import BackButton from '@/components/back-button';
import { currentUser } from '@/lib/authentication';
import PortfolioForm from '@/components/secured/portfolio-form';
import {
Card,
Expand All @@ -17,16 +17,16 @@ export default async function PortfolioIdPage({
}: {
params: { portfolioId: string };
}) {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const portfolio = await prismadb.portfolio.findUnique({
where: {
id: params.portfolioId,
userId: session.user.id
userId: user.id
},
include: {
tags: true
Expand Down
12 changes: 6 additions & 6 deletions app/(secured)/admin/(routes)/portfolio/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ComponentType } from 'react';
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import { DataTable } from '@/components/data-table/data-table';
import { columns } from '@/components/secured/portfolio-table/columns';
import AddButton from '@/components/secured/portfolio-table/add-button';
Expand All @@ -12,7 +13,6 @@ import {
CardHeader,
CardTitle
} from '@/components/ui/card';
import { ComponentType } from 'react';

const filterOptions: {
label: string;
Expand All @@ -21,15 +21,15 @@ const filterOptions: {
}[] = [];

export default async function PortfolioPage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const portfolios = await prismadb.portfolio.findMany({
where: {
userId: session?.user?.id
userId: user.id
},
orderBy: {
createdAt: 'desc'
Expand Down
10 changes: 5 additions & 5 deletions app/(secured)/admin/(routes)/qualification/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from 'next/navigation';

import { auth } from '@/lib/auth';
import prismadb from '@/lib/prismadb';
import { currentUser } from '@/lib/authentication';
import { DataTable } from '@/components/data-table/data-table';
import { columns } from '@/components/secured/qualification-table/columns';
import AddButton from '@/components/secured/qualification-table/add-button';
Expand All @@ -25,15 +25,15 @@ const filterOptions = [
];

export default async function QualificationPage() {
const session = await auth();
const user = await currentUser();

if (!session || !session.user || !session.user.id) {
redirect('/api/auth/signin');
if (!user || !user.id) {
redirect('/auth/sign-in');
}

const qualifications = await prismadb.qualification.findMany({
where: {
userId: session?.user?.id
userId: user.id
},
orderBy: {
createdAt: 'asc'
Expand Down
Loading

0 comments on commit 7abd901

Please sign in to comment.