Skip to content

Commit

Permalink
getProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
nouzoehiroaki committed Jan 31, 2024
1 parent cb33c16 commit 996c22f
Show file tree
Hide file tree
Showing 18 changed files with 1,347 additions and 925 deletions.
17 changes: 17 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

# DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
POSTGRES_URL="postgres://default:rN48DOesBjYm@ep-broad-violet-a1sf9fmb-pooler.ap-southeast-1.postgres.vercel-storage.com:5432/verceldb"
POSTGRES_PRISMA_URL="postgres://default:rN48DOesBjYm@ep-broad-violet-a1sf9fmb-pooler.ap-southeast-1.postgres.vercel-storage.com:5432/verceldb?pgbouncer=true&connect_timeout=15"
POSTGRES_URL_NON_POOLING="postgres://default:rN48DOesBjYm@ep-broad-violet-a1sf9fmb.ap-southeast-1.postgres.vercel-storage.com:5432/verceldb"
POSTGRES_USER="default"
POSTGRES_HOST="ep-broad-violet-a1sf9fmb-pooler.ap-southeast-1.postgres.vercel-storage.com"
POSTGRES_PASSWORD="rN48DOesBjYm"
POSTGRES_DATABASE="verceldb"
NEXTAUTH_SECRET="xZPVRnEXCktiL7XAS6Y0f3jYk54eNNbXXbGaqscviGQ="
GITHUB_ID="08c968f9e0d2ddfa8f6a"
GITHUB_SECRET="5b72acfc96c9299ec140e628fe132a0c11be56c6"
1,658 changes: 881 additions & 777 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"prepare": "husky install"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^5.9.0",
"@vercel/postgres": "^0.7.2",
"next": "14.1.0",
"next-auth": "^4.24.5",
"react": "^18",
"react-dom": "^18"
},
Expand All @@ -35,12 +39,17 @@
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"postcss": "^8",
"prisma": "^5.9.0",
"tailwindcss": "^3.3.0",
"typescript": "^5",
"vitest": "^1.2.1"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md}": ["eslint --fix"]
"*.{js,jsx,ts,tsx,md}": [
"eslint --fix"
]
},
"ignorePatterns": ["!.storybook"]
"ignorePatterns": [
"!.storybook"
]
}
79 changes: 79 additions & 0 deletions prisma/migrations/20240131144102_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
-- CreateTable
CREATE TABLE "Account" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"type" TEXT NOT NULL,
"provider" TEXT NOT NULL,
"providerAccountId" TEXT NOT NULL,
"refresh_token" TEXT,
"access_token" TEXT,
"expires_at" INTEGER,
"token_type" TEXT,
"scope" TEXT,
"id_token" TEXT,
"session_state" TEXT,

CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Session" (
"id" TEXT NOT NULL,
"sessionToken" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"expires" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"name" TEXT,
"email" TEXT,
"emailVerified" TIMESTAMP(3),
"image" TEXT,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Purchase" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"bookId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Purchase_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "VerificationToken" (
"identifier" TEXT NOT NULL,
"token" TEXT NOT NULL,
"expires" TIMESTAMP(3) NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");

-- CreateIndex
CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken");

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token");

-- CreateIndex
CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token");

-- AddForeignKey
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Purchase" ADD CONSTRAINT "Purchase_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
67 changes: 67 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL")
directUrl = env("POSTGRES_URL_NON_POOLING")
shadowDatabaseUrl = env("POSTGRES_URL_NON_POOLING")
}

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
purchases Purchase[]
}

model Purchase {
id String @id @default(cuid())
userId String
bookId String
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
Binary file added public/default_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

Binary file added public/thumbnails/450x350.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import NextAuth from 'next-auth';

import { nextAuthOptions } from '@/lib/next-auth/option';

const handler = NextAuth(nextAuthOptions);

export { handler as GET, handler as POST };
36 changes: 3 additions & 33 deletions src/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
17 changes: 11 additions & 6 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import './globals.css';

import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { Noto_Sans_JP } from 'next/font/google';

const inter = Inter({ subsets: ['latin'] });
import Header from '@/components/layouts/Header/Header';

const notoSansJP = Noto_Sans_JP({ weight: '400', subsets: ['latin'] });

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
title: 'kge book commerce',
description: 'kgeが書いた有料記事です',
};

export default function RootLayout({
Expand All @@ -16,8 +18,11 @@ export default function RootLayout({
children: React.ReactNode;
}>) {
return (
<html lang='en'>
<body className={inter.className}>{children}</body>
<html lang='ja'>
<body className={notoSansJP.className}>
<Header />
{children}
</body>
</html>
);
}
61 changes: 61 additions & 0 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use client';
import { getProviders, signIn } from 'next-auth/react';
import { useEffect, useState } from 'react';

type Provider = {
id: string;
name: string;
};

type Providers = {
[provider: string]: Provider;
};

// eslint-disable-next-line @next/next/no-async-client-component
function Login() {
const [providers, setProviders] = useState<Providers | null>(null);
useEffect(() => {
getProviders().then((res) => {
console.log(res);
setProviders(res);
});
}, []);
return (
<div className='flex items-center justify-center py-16 px-4 sm:px-6 lg:px-8'>
<div className='max-w-md w-full space-y-8'>
<div>
<h2 className='mt-6 text-center text-3xl font-extrabold text-gray-900'>
アカウントにログイン
</h2>
</div>
<div className='mt-8 space-y-6'>
{providers &&
Object.values(providers).map((provider: Provider) => {
return (
<div key={provider.id} className='text-center'>
<button
onClick={() => signIn(provider.id, { callbackUrl: '/' })}
className='bg-gray-900 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded flex items-center justify-center w-full'
>
<svg
role='img'
viewBox='0 0 24 24'
xmlns='http://www.w3.org/2000/svg'
className='w-6 h-6 mr-2'
fill='currentColor'
>
<title>GitHub icon</title>
<path d='M12 0C5.373 0 0 5.373 0 12c0 5.302 3.438 9.8 8.205 11.387.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.723-4.042-1.608-4.042-1.608-.546-1.386-1.332-1.754-1.332-1.754-1.087-.743.083-.728.083-.728 1.205.085 1.84 1.236 1.84 1.236 1.07 1.835 2.807 1.305 3.492.998.108-.775.42-1.305.763-1.605-2.665-.3-5.467-1.332-5.467-5.93 0-1.31.468-2.382 1.235-3.22-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.3 1.23.956-.266 1.98-.398 3-.403 1.02.005 2.044.137 3 .403 2.29-1.552 3.297-1.23 3.297-1.23.653 1.652.242 2.873.118 3.176.768.838 1.234 1.91 1.234 3.22 0 4.61-2.805 5.625-5.475 5.92.43.372.824 1.102.824 2.222 0 1.604-.015 2.897-.015 3.29 0 .322.216.697.825.577C20.565 21.795 24 17.298 24 12c0-6.627-5.373-12-12-12z' />
</svg>
<span>Githubでログイン</span>
</button>
</div>
);
})}
</div>
</div>
</div>
);
}

export default Login;
Loading

0 comments on commit 996c22f

Please sign in to comment.