Skip to content

Commit

Permalink
user login functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
lryanle committed Nov 10, 2023
1 parent c42c2b9 commit 4cd25f2
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 89 deletions.
92 changes: 40 additions & 52 deletions frontend/app/api/auth/[...nextauth]/authOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,26 @@ export const authOptions: NextAuthOptions = {
GitHubProvider({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
username: profile.login,
email: profile.email,
image: profile.avatar_url,
followers: profile.followers,
verified: true,
};
},
}),
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
username: profile.login,
email: profile.email,
image: profile.avatar_url,
followers: profile.followers,
verified: true,
};
},
}),
LinkedInProvider({
clientId: process.env.LINKEDIN_CLIENT_ID as string,
clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string,
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
username: profile.login,
email: profile.email,
image: profile.avatar_url,
followers: profile.followers,
verified: true,
};
},
// profile(profile) {
// return {
// id: profile.id.toString(),
// name: profile.name ?? profile.login,
// email: profile.email,
// image: profile.avatar_url
// };
// },
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
username: profile.login,
email: profile.email,
image: profile.avatar_url,
followers: profile.followers,
verified: true,
};
},
// profile(profile) {
// return {
// id: profile.id.toString(),
// name: profile.name ?? profile.login,
// email: profile.email,
// image: profile.avatar_url
// };
// },
authorization: {
params: {
prompt: "consent",
Expand All @@ -77,6 +41,30 @@ export const authOptions: NextAuthOptions = {
}
}
}),
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
// profile(profile) {
// return {
// id: profile.id.toString(),
// name: profile.name ?? profile.login,
// email: profile.email,
// image: profile.avatar_url
// };
// },
}),
LinkedInProvider({
clientId: process.env.LINKEDIN_CLIENT_ID as string,
clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string,
// profile(profile) {
// return {
// id: profile.id.toString(),
// name: profile.name ?? profile.login,
// email: profile.email,
// image: profile.avatar_url
// };
// },
}),
// CredentialsProvider({
// name: "credentials",
// credentials: {
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/layout/user-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use client";

import { useState } from "react";
import { signOut } from "next-auth/react";
import { LayoutDashboard, LogOut } from "lucide-react";
import Popover from "@/components/shared/popover";
import Image from "next/image";
import { LayoutDashboard, LogOut } from "lucide-react";
import { Session } from "next-auth";
import { signOut } from "next-auth/react";
import Image from "next/image";
import { useState } from "react";

export default function UserDropdown({ session }: { session: Session }) {
const { email, image } = session?.user || {};
const { email, image, name } = session?.user || {};
const [openPopover, setOpenPopover] = useState(false);

if (!email) return null;
Expand Down
152 changes: 120 additions & 32 deletions frontend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,142 @@ datasource db {
}


// model Account {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// userId String @db.ObjectId
// type String
// provider String
// providerAccountId String
// refresh_token String?
// access_token String?
// expires_at Int?
// token_type String?
// scope String?
// id_token String?
// session_state String?
// oauth_token_secret String?
// oauth_token String?

// user User @relation(fields: [userId], references: [id], onDelete: Cascade)

// @@unique([provider, providerAccountId])
// }

// model User {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// name String?
// username String?
// email String @unique
// createdAt DateTime @default(now())
// emailVerified DateTime? @map("verifiedAt")
// image String?
// Account Account[]
// Session Session[]
// @@map("users")
// }

// model Session {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// sessionToken String @unique
// userId String @db.ObjectId
// expires DateTime @map("expiresAt")
// user User @relation(fields: [userId], references: [id])
// @@map("Session")
// }

// model VerificationToken {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// identifier String
// token String @unique
// expires DateTime @map("expiresAt")
// @@unique([identifier, token])
// @@map("verification_tokens")
// }

// --------------------


model Account {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String @db.ObjectId
userId String @map("user_id") @db.ObjectId
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
providerAccountId String @map("provider_account_id")
refresh_token String? @db.String
access_token String? @db.String
expires_at Int?
token_type String?
scope String?
id_token String?
id_token String? @db.String
session_state String?
oauth_token_secret String?
oauth_token String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}

model Session {
id String @id @default(auto()) @map("_id") @db.ObjectId
sessionToken String @unique @map("session_token")
userId String @map("user_id") @db.ObjectId
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("sessions")
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
username String
email String @unique
createdAt DateTime @default(now())
emailVerified DateTime? @map("verifiedAt")
image String?
Account Account[]
Session Session[]
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
email String? @unique
emailVerified DateTime? @map("email_verified")
image String?
accounts Account[]
sessions Session[]
@@map("users")
}

model Session {
id String @id @default(auto()) @map("_id") @db.ObjectId
sessionToken String @unique
userId String @db.ObjectId
expires DateTime @map("expiresAt")
user User @relation(fields: [userId], references: [id])
@@map("Session")
}


model VerificationToken {
id String @id @default(auto()) @map("_id") @db.ObjectId
identifier String
token String @unique
expires DateTime @map("expiresAt")
identifier String @id @map("_id")
token String @unique
expires DateTime
@@unique([identifier, token])
@@map("verification_tokens")
}
@@map("verificationtokens")
}

// ---------

// model User {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// name String?
// email String? @unique
// emailVerified DateTime?
// image String?
// hashedPassword String?
// createdAt DateTime @default(now())
// updatedAt DateTime @updatedAt

// accounts Account[]
// }

// model Account {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// userId String @db.ObjectId
// type String
// provider String
// providerAccountId String
// refresh_token String? @db.String
// access_token String? @db.String
// expires_at Int?
// token_type String?
// scope String?
// id_token String? @db.String
// session_state String?

// user User @relation(fields: [userId], references: [id], onDelete: Cascade)

// @@unique([provider, providerAccountId])
// }

0 comments on commit 4cd25f2

Please sign in to comment.