Skip to content

Commit 9e0517f

Browse files
authored
๐Ÿ”€: ํšŒ์›๊ฐ€์ž…์˜ ๋””ํ…Œ์ผํ•œ raw_user_meta_data๋ฅผ ์„ค์ •ํ•œ๋‹ค. (#28)
* ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐Ÿ”ง: pnpm์œผ๋กœ CRA template TypeScript๋ฅผ ์„ค์น˜ํ•˜๊ณ  eslint ๊ทœ์น™ ์ ์šฉ * ๐Ÿ”ง: react-router-dom ์„ค์น˜ ํ›„ ์ปดํฌ๋„ŒํŠธ ์—ฐ๊ฒฐ ๋ฐ ์ „์ฒด์ ์ธ ํ…Œ์ŠคํŠธ ๊ฒ€ํ†  ์™„๋ฃŒ * ๐Ÿ”ง: pnpm์œผ๋กœ mono-repo ๊ตฌํ˜„ * ๐Ÿ”ง: supabase์™€ axios, tanstackquery ์„ค์น˜ * โœจ: Signup ํŽ˜์ด์ง€ ๊ตฌํ˜„ ๋ฐ Post์š”์ฒญ ํ™•์ธ * ๐Ÿ”ง: dotenv ์„ค์น˜ * โœจ: env ํŒŒ์ผ ignore์— ์ถ”๊ฐ€ * โœจ: ์ฝ”๋“œ ์ˆ˜์ • * โœจ: fetchํ•จ์ˆ˜ ํ™•์ธ ๋ฐ post ํ…Œ์ŠคํŠธ, 500 ์—๋Ÿฌ
1 parent 24f4ca1 commit 9e0517f

File tree

7 files changed

+150
-72
lines changed

7 files changed

+150
-72
lines changed

โ€Žfront/.gitignoreโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/node_modules
55
/.pnp
66
.pnp.js
7-
7+
.env
88
# testing
99
/coverage
1010

โ€Žfront/package.jsonโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@types/react-dom": "^18.3.1",
1515
"axios": "^1.7.8",
1616
"class-variance-authority": "^0.7.0",
17+
"dotenv": "^16.4.5",
1718
"react": "^18.3.1",
1819
"react-dom": "^18.3.1",
1920
"react-router-dom": "^7.0.1",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import supabaseInstance from '../Model/fetch.supabase.instance';
2+
3+
interface SignUpParams {
4+
email: string;
5+
password: string;
6+
admin: boolean;
7+
job?: string; // Optional: name์€ ํ•„์ˆ˜๊ฐ€ ์•„๋‹ ์ˆ˜ ์žˆ์Œ
8+
nickname?: string;
9+
}
10+
11+
const fetchSignUp = async ({ email, password, admin, job, nickname }: SignUpParams) => {
12+
try {
13+
const { data, error } = await supabaseInstance.auth.signUp({
14+
email,
15+
password,
16+
options: {
17+
data: {
18+
// ์‚ฌ์šฉ์ž ์ •์˜ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋กœ ์ „๋‹ฌ
19+
admin,
20+
job,
21+
nickname,
22+
},
23+
},
24+
});
25+
26+
// ๊ตฌ์กฐํ• ๋‹น์œผ๋กœ responseMessage๋ฅผ ๋ณด๋‚ด๋Š” ์ด์œ ๋Š” ์ด ๊ตฌ์กฐ๋กœ ํ˜ธ์ถœํ•˜๋Š” ์ชฝ์—์„œ ๋ช…ํ™•ํ•˜๊ฒŒ responseMessage์™€ data๋ฅผ ๊ตฌ๋ถ„ํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ์ด๋‹ค. ์ฆ‰, ๋ฐ˜ํ™˜ ๊ฐ’์€ ๊ฐ์ฒด์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
27+
// ์ถ”๊ฐ€์ ์œผ๋กœ fetchSignup์€ promise๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ๋‹ค.
28+
29+
if (error) {
30+
// error
31+
console.error('SignUp Error:', error);
32+
const errorMessage = error.message || 'Signup failed. Please try again.';
33+
return { responseMessage: errorMessage, data: undefined };
34+
}
35+
// ์„ฑ๊ณต์ ์ธ ๊ฒฝ์šฐ
36+
const successMessage = 'Signup successful! Check your email for confirmation.';
37+
return { responseMessage: successMessage, data };
38+
39+
// ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ
40+
} catch (error: any) {
41+
console.error('SignUp Error:', error);
42+
const catchMessage = error.message || 'An unexpected error occurred. Please try again.';
43+
return { responseMessage: catchMessage, data: undefined };
44+
}
45+
};
46+
47+
export default fetchSignUp;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import axios from 'axios';
2+
3+
const axiosInstance = axios.create({
4+
baseURL: 'https://fsrotjrwllkimiidizgk.supabase.co', // Supabase ํ”„๋กœ์ ํŠธ URL
5+
headers: {
6+
apikey:
7+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZzcm90anJ3bGxraW1paWRpemdrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzMwMjgzMTQsImV4cCI6MjA0ODYwNDMxNH0.uiFog4O3BbOZhBC1z0LRFTtEE4p4z3PK5VQ5wKrRHzg', // Supabase API Key
8+
'Content-Type': 'application/json',
9+
},
10+
});
11+
12+
export default axiosInstance;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createClient } from '@supabase/supabase-js';
2+
3+
const supabaseInstance = createClient(
4+
'https://bsrffkqymaqhwwqziqee.supabase.co',
5+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJzcmZma3F5bWFxaHd3cXppcWVlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzMxMTc5NzMsImV4cCI6MjA0ODY5Mzk3M30.1UKuqvG0Ls3WxLvNkAHRASWyv8Y8coIJKe0M9tZ8flA',
6+
);
7+
8+
export default supabaseInstance;

โ€Žfront/src/Page/Signup.tsxโ€Ž

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,77 @@
11
import React, { useState } from 'react';
2-
import { createClient } from '@supabase/supabase-js';
2+
import fetchSignUp from '../Controller/fetch.signup';
33

4-
const supabase = createClient(
5-
'https://fsrotjrwllkimiidizgk.supabase.co',
6-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZzcm90anJ3bGxraW1paWRpemdrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzMwMjgzMTQsImV4cCI6MjA0ODYwNDMxNH0.uiFog4O3BbOZhBC1z0LRFTtEE4p4z3PK5VQ5wKrRHzg',
7-
);
8-
9-
const Signup: React.FC = () => {
4+
const Login = () => {
105
const [email, setEmail] = useState('');
116
const [password, setPassword] = useState('');
12-
const [name, setName] = useState('');
7+
const [admin, setAdmin] = useState(false);
8+
const [job, setJob] = useState('');
9+
const [nickname, setNickName] = useState('');
1310
const [responseMessage, setResponseMessage] = useState('');
1411

1512
const handleSignUp = async () => {
16-
try {
17-
const { data, error } = await supabase.auth.signUp({
18-
email,
19-
password,
20-
options: {
21-
data: {
22-
name, // ์‚ฌ์šฉ์ž ์ •์˜ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋กœ ์ „๋‹ฌ
23-
},
24-
},
25-
});
26-
27-
if (error) {
28-
throw error;
29-
}
30-
31-
setResponseMessage('Signup successful! Check your email for confirmation.');
32-
} catch (error: any) {
33-
setResponseMessage(error.message || 'Signup failed. Please try again.');
34-
}
13+
const { responseMessage } = await fetchSignUp({
14+
email,
15+
password,
16+
admin,
17+
job,
18+
nickname,
19+
});
20+
setResponseMessage(responseMessage);
3521
};
3622

3723
return (
38-
<div style={{ maxWidth: '400px', margin: 'auto', padding: '20px' }}>
39-
<h1>Sign Up</h1>
24+
<div className='max-w-md p-5 mx-auto'>
25+
<h1 className='mb-5 text-2xl font-bold'>Sign Up</h1>
26+
{/* Nickname */}
4027
<input
4128
type='text'
42-
placeholder='Name'
43-
value={name}
44-
onChange={(e) => setName(e.target.value)}
45-
style={{ display: 'block', width: '100%', marginBottom: '10px', padding: '8px' }}
29+
placeholder='nickname'
30+
value={nickname}
31+
onChange={(e) => setNickName(e.target.value)}
32+
className='block w-full p-2 mb-3 border border-gray-300 rounded'
4633
/>
34+
{/* Job */}
35+
<select
36+
value={job}
37+
onChange={(e) => setJob(e.target.value)}
38+
className='block w-full p-2 mb-3 border border-gray-300 rounded'
39+
>
40+
<option value=''>Select your job</option>
41+
<option value='Front-Developer'>ํ”„๋ก ํŠธ ๊ฐœ๋ฐœ์ž</option>
42+
<option value='Back-Developer'>๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž</option>
43+
<option value='Full-Developer'>ํ’€์Šคํƒ ๊ฐœ๋ฐœ์ž</option>
44+
<option value='Designer'>๋””์ž์ด๋„ˆ</option>
45+
<option value='Manager'>๊ธฐํš์ž</option>
46+
<option value='Student'>ํ•™์ƒ</option>
47+
</select>
48+
{/* Email */}
4749
<input
4850
type='email'
4951
placeholder='Email'
5052
value={email}
5153
onChange={(e) => setEmail(e.target.value)}
52-
style={{ display: 'block', width: '100%', marginBottom: '10px', padding: '8px' }}
54+
className='block w-full p-2 mb-3 border border-gray-300 rounded'
5355
/>
56+
{/* Password */}
5457
<input
5558
type='password'
5659
placeholder='Password'
5760
value={password}
5861
onChange={(e) => setPassword(e.target.value)}
59-
style={{ display: 'block', width: '100%', marginBottom: '10px', padding: '8px' }}
62+
className='block w-full p-2 mb-3 border border-gray-300 rounded'
6063
/>
64+
{/* Sign Up Button */}
6165
<button
6266
onClick={handleSignUp}
6367
type='button'
64-
style={{
65-
width: '100%',
66-
padding: '10px',
67-
backgroundColor: '#007bff',
68-
color: 'white',
69-
border: 'none',
70-
borderRadius: '5px',
71-
}}
68+
className='w-full p-3 font-bold text-white bg-blue-500 rounded hover:bg-blue-600'
7269
>
7370
Sign Up
7471
</button>
75-
{responseMessage && <p style={{ marginTop: '20px', color: 'red' }}>{responseMessage}</p>}
72+
{responseMessage && <p className='mt-5 text-red-500'>{responseMessage}</p>}
7673
</div>
7774
);
7875
};
7976

80-
export default Signup;
77+
export default Login;

0 commit comments

Comments
ย (0)