Skip to content

Commit

Permalink
Merge branch 'main' into feat/bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nimit9 authored Mar 20, 2024
2 parents 456e43a + 8125ae2 commit c5e248b
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 509 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.7",
"@types/bcrypt": "^5.0.2",
"@types/jsonwebtoken": "^9.0.5",
"axios": "^1.6.2",
"bcrypt": "^5.1.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"dayjs": "^1.11.10",
Expand Down
2 changes: 2 additions & 0 deletions prisma/migrations/20240319182925_test/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Comment" ADD COLUMN "isPinned" BOOLEAN NOT NULL DEFAULT false;
2 changes: 2 additions & 0 deletions prisma/migrations/20240319183729_add_password/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "password" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "appxUserId" TEXT,
ADD COLUMN "appxUsername" TEXT;
3 changes: 3 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ model User {
discordConnect DiscordConnect?
disableDrm Boolean @default(false)
bookmarks Bookmark[]
password String?
appxUserId String?
appxUsername String?
}

model DiscordConnect {
Expand Down
2 changes: 1 addition & 1 deletion src/components/VideoPlayer2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import './QualitySelectorControllBar';

// todo correct types
interface VideoPlayerProps {
setQuality: React.Dispatch<React.SetStateAction<number>>;
setQuality: React.Dispatch<React.SetStateAction<string>>;
options: any;
onReady?: (player: Player) => void;
subtitles?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/VideoPlayerSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Thumbnail {
}

interface VideoProps {
setQuality: React.Dispatch<React.SetStateAction<number>>;
setQuality: React.Dispatch<React.SetStateAction<string>>;
thumbnails: Thumbnail[];
segments: Segment[];
subtitles: string;
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/ContentRendererClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const ContentRendererClient = ({
const router = useRouter();

//@ts-ignore
const [quality, setQuality] = useState<number>(
searchParams.get('quality') | null,
const [quality, setQuality] = useState<string>(
searchParams.get('quality') ?? '1080',
);

if (!metadata) {
Expand Down
77 changes: 58 additions & 19 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import db from '@/db';
import CredentialsProvider from 'next-auth/providers/credentials';
import { SignJWT, importJWK } from 'jose';
import { Cache } from '@/db/Cache';
import bcrypt from 'bcrypt';
import prisma from '@/db';

interface AppxSigninResponse {
data: {
userid: string;
name: string;
username: string;
};
}

const generateJWT = async (payload: any) => {
const secret = process.env.JWT_SECRET || 'secret';
Expand Down Expand Up @@ -82,27 +91,54 @@ export const authOptions = {
},
async authorize(credentials: any) {
try {
let user = await Cache.getInstance().get('auth', [
const hashedPassword = await bcrypt.hash(credentials.password, 10);

const userDb = await prisma.user.findFirst({
where: {
email: credentials.username,
},
select: {
password: true,
id: true,
name: true,
},
});
if (
userDb &&
userDb.password &&
(await bcrypt.compare(credentials.password, userDb.password))
) {
const jwt = await generateJWT({
id: userDb.id,
});
await db.user.update({
where: {
id: userDb.id,
},
data: {
token: jwt,
},
});

return {
id: userDb.id,
name: userDb.name,
email: credentials.username,
token: jwt,
};
}
console.log('not in db');
//@ts-ignore
const user: AppxSigninResponse = await validateUser(
credentials.username,
credentials.password,
]);
if (!user) {
//@ts-ignore
user = await validateUser(
credentials.username,
credentials.password,
);
Cache.getInstance().set(
'auth',
[credentials.username, credentials.password],
user,
60 * 60 * 24,
);
}
);

const jwt = await generateJWT({
id: user.data.userid,
});

if (user.data) {
const jwt = await generateJWT({
id: user.data.userid,
});
try {
await db.user.upsert({
where: {
Expand All @@ -113,12 +149,14 @@ export const authOptions = {
name: user.data.name,
email: credentials.username,
token: jwt,
password: hashedPassword,
},
update: {
id: user.data.userid,
name: user.data.name,
email: credentials.username,
token: jwt,
password: hashedPassword,
},
});
} catch (e) {
Expand All @@ -132,6 +170,7 @@ export const authOptions = {
token: jwt,
};
}

// Return null if user data could not be retrieved
return null;
} catch (e) {
Expand Down
Loading

0 comments on commit c5e248b

Please sign in to comment.