Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

206 oauthの認証ボタン作るます #216

Merged
merged 11 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node
# TODO: node20のバグを修正したら消す
# https://github.com/nodejs/node/issues/47822
FROM node:19.9.0

WORKDIR /workdir

Expand Down
113 changes: 112 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"eslint-config-next": "13.4.1",
"jotai": "^2.1.0",
"next": "13.4.1",
"next-auth": "^4.22.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"socket.io-client": "^4.6.1",
Expand Down
Binary file modified frontend/src/__image_snapshots__/app--basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/app/__image_snapshots__/app-page--basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions frontend/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import FortyTwoProvider from 'next-auth/providers/42-school';
import CredentialsProvider from 'next-auth/providers/credentials';
const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID || '',
clientSecret: process.env.GOOGLE_CLIENT_SECRET || '',
}),
FortyTwoProvider({
clientId: process.env.FORTY_TWO_CLIENT_ID || '',
clientSecret: process.env.FORTY_TWO_CLIENT_SECRET || '',
}),
CredentialsProvider({
name: 'Email',
credentials: {
email: {
label: 'Email',
type: 'email',
placeholder: 'example@example.com',
},
password: { label: 'Password', type: 'password' },
},
async authorize(credentials, req) {
// backendにリクエストを送る
console.log(credentials);
console.log(req);
const user = { id: '1', name: 'hoge', email: 'example@example.com' };
if (user) {
return user;
}
return null;
},
}),
],
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
console.log(user);
console.log(account);
console.log(profile);
console.log(email);
console.log(credentials);
return true;
},
},
});

export { handler as GET, handler as POST };
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 frontend/src/features/user/components/User.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactNode } from 'react';
import { useAtom } from 'jotai';
import { signIn } from 'next-auth/react';

import { Container } from '@/components/Layout/Container';
import { userInfoAtom } from '@/App';
Expand Down Expand Up @@ -28,6 +29,9 @@ export const User = ({ children }: { children: ReactNode }) => {
);
}
};
const AuthLoginButton = () => {
return <button onClick={() => signIn()}>authlogin</button>;
};

return (
<Container flexDirection="column">
Expand All @@ -39,6 +43,9 @@ export const User = ({ children }: { children: ReactNode }) => {
<div style={{ margin: 'auto 10px auto auto' }}>
<UserInputArea />
</div>
<div>
<AuthLoginButton />
</div>
</Container>
</div>
<hr />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.