Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky committed Oct 18, 2024
1 parent c6e3871 commit d122def
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 45 deletions.
4 changes: 2 additions & 2 deletions app/(auth)/login/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';

import { Route } from 'next';
import type { Route } from 'next';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { getSafeReturnToPath } from '../../../util/validation';
import { LoginResponseBodyPost } from '../api/login/route';
import type { LoginResponseBodyPost } from '../api/login/route';

export default function LoginForm(props: { returnTo?: string | string[] }) {
const [username, setUsername] = useState('');
Expand Down
2 changes: 1 addition & 1 deletion app/LinkIfNotCurrent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import Link, { LinkProps } from 'next/link';
import Link, { type LinkProps } from 'next/link';
import { usePathname } from 'next/navigation';

export default function LinkIfNotCurrent<RouteType>({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import {
BlogPost,
type BlogPost,
getPublishedBlogPostsBySessionToken,
} from '../../../../database/blogPosts';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import {
BlogPost,
type BlogPost,
getPublishedBlogPosts,
} from '../../../../database/blogPosts';
import { getUserByValidSessionToken } from '../../../../database/users';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import {
BlogPost,
type BlogPost,
getPublishedBlogPosts,
} from '../../../../database/blogPosts';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import {
BlogPost,
type BlogPost,
getUnpublishedBlogPostsBySessionToken,
} from '../../../../database/blogPosts';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import {
BlogPost,
type BlogPost,
getUnpublishedBlogPostsByUserId,
} from '../../../../database/blogPosts';
import { getUserByValidSessionToken } from '../../../../database/users';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import {
BlogPost,
type BlogPost,
getUnpublishedBlogPosts,
} from '../../../../database/blogPosts';
import { getUserByValidSessionToken } from '../../../../database/users';
Expand Down
2 changes: 1 addition & 1 deletion app/api/example-5-secrets-exposure/solution-2/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { getUserByValidSessionToken } from '../../../../database/users';
import { Colors } from '../../../example-5-secrets-exposure/common';
import type { Colors } from '../../../example-5-secrets-exposure/common';

export const dynamic = 'force-dynamic';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { notFound } from 'next/navigation';
import { useEffect, useState } from 'react';
import { BlogPost } from '../../../database/blogPosts';
import { MissingAuthenticationApiRouteResponseBodyGet } from '../../api/example-1-missing-authentication-route-handler/solution-1/route';
import type { BlogPost } from '../../../database/blogPosts';
import type { MissingAuthenticationApiRouteResponseBodyGet } from '../../api/example-1-missing-authentication-route-handler/solution-1/route';
import LinkIfNotCurrent from '../../LinkIfNotCurrent';

type Props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlogPost } from '../../database/blogPosts';
import type { BlogPost } from '../../database/blogPosts';
import LinkIfNotCurrent from '../LinkIfNotCurrent';

type Props =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { notFound } from 'next/navigation';
import { useEffect, useState } from 'react';
import { BlogPost } from '../../../database/blogPosts';
import { MissingAuthorizationApiRouteResponseBodyGet } from '../../api/example-3-missing-authorization-route-handler/solution-1/route';
import type { BlogPost } from '../../../database/blogPosts';
import type { MissingAuthorizationApiRouteResponseBodyGet } from '../../api/example-3-missing-authorization-route-handler/solution-1/route';
import LinkIfNotCurrent from '../../LinkIfNotCurrent';

type Props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';

import { useEffect, useState } from 'react';
import { BlogPost } from '../../../database/blogPosts';
import { User } from '../../../database/users';
import { MissingAuthorizationApiRouteResponseBodyGet } from '../../api/example-3-missing-authorization-route-handler/solution-1/route';
import type { BlogPost } from '../../../database/blogPosts';
import type { User } from '../../../database/users';
import type { MissingAuthorizationApiRouteResponseBodyGet } from '../../api/example-3-missing-authorization-route-handler/solution-1/route';
import LinkIfNotCurrent from '../../LinkIfNotCurrent';

type Props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { BlogPost } from '../../../database/blogPosts';
import type { BlogPost } from '../../../database/blogPosts';

type Props = {
blogPosts: BlogPost[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { BlogPost } from '../../../database/blogPosts';
import { User } from '../../../database/users';
import type { BlogPost } from '../../../database/blogPosts';
import type { User } from '../../../database/users';

type Props = {
blogPosts: BlogPost[];
Expand Down
2 changes: 1 addition & 1 deletion app/example-5-secrets-exposure/common.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from '../../database/users';
import type { User } from '../../database/users';
import LinkIfNotCurrent from '../LinkIfNotCurrent';

export type Colors = {
Expand Down
2 changes: 1 addition & 1 deletion app/example-5-secrets-exposure/solution-1/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getUsers } from '../../../database/users';
import Common, { Colors } from '../common';
import Common, { type Colors } from '../common';

export const dynamic = 'force-dynamic';

Expand Down
4 changes: 2 additions & 2 deletions app/example-5-secrets-exposure/solution-2/SecretsExposure.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import { User } from '../../../database/users';
import Common, { Colors } from '../common';
import type { User } from '../../../database/users';
import Common, { type Colors } from '../common';

type Props = {
users: User[];
Expand Down
5 changes: 3 additions & 2 deletions app/example-5-secrets-exposure/vulnerable/SecretsExposure.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client';

import { useEffect, useState } from 'react';
import { User } from '../../../database/users';
import Common, { Colors } from '../common';
import type { User } from '../../../database/users';
import Common, { type Colors } from '../common';

type Props = {
apiKey: string;
Expand Down
2 changes: 1 addition & 1 deletion migrations/001-create-table-users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Sql } from 'postgres';
import type { Sql } from 'postgres';

const users = [
{
Expand Down
15 changes: 7 additions & 8 deletions migrations/002-create-table-sessions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Sql } from 'postgres';
import type { Sql } from 'postgres';

export async function up(sql: Sql<Record<string, string>>) {
await sql`
CREATE TABLE
sessions (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
token VARCHAR(90) UNIQUE NOT NULL,
expiry_timestamp TIMESTAMP NOT NULL DEFAULT now () + INTERVAL '24 hours',
user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE
);
CREATE TABLE sessions (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
token VARCHAR(90) UNIQUE NOT NULL,
expiry_timestamp TIMESTAMP NOT NULL DEFAULT now() + INTERVAL '24 hours',
user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE
);
`;
}

Expand Down
17 changes: 8 additions & 9 deletions migrations/003-create-table-blog-posts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Sql } from 'postgres';
import type { Sql } from 'postgres';

const blogPosts = [
{
Expand Down Expand Up @@ -54,14 +54,13 @@ const blogPosts = [

export async function up(sql: Sql<Record<string, string>>) {
await sql`
CREATE TABLE
IF NOT EXISTS blog_posts (
id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
title VARCHAR(100) NOT NULL,
text_content VARCHAR(2000) NOT NULL,
is_published BOOLEAN NOT NULL DEFAULT FALSE,
user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE
)
CREATE TABLE IF NOT EXISTS blog_posts (
id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
title VARCHAR(100) NOT NULL,
text_content VARCHAR(2000) NOT NULL,
is_published BOOLEAN NOT NULL DEFAULT FALSE,
user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE
)
`;

for (const blogPost of blogPosts) {
Expand Down

0 comments on commit d122def

Please sign in to comment.