|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { createClient } from '@supabase/supabase-js'; |
| 3 | + |
| 4 | +const supabase = createClient( |
| 5 | + 'https://fsrotjrwllkimiidizgk.supabase.co', |
| 6 | + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZzcm90anJ3bGxraW1paWRpemdrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzMwMjgzMTQsImV4cCI6MjA0ODYwNDMxNH0.uiFog4O3BbOZhBC1z0LRFTtEE4p4z3PK5VQ5wKrRHzg', |
| 7 | +); |
| 8 | + |
| 9 | +const Signup: React.FC = () => { |
| 10 | + const [email, setEmail] = useState(''); |
| 11 | + const [password, setPassword] = useState(''); |
| 12 | + const [name, setName] = useState(''); |
| 13 | + const [responseMessage, setResponseMessage] = useState(''); |
| 14 | + |
| 15 | + 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 | + } |
| 35 | + }; |
| 36 | + |
| 37 | + return ( |
| 38 | + <div style={{ maxWidth: '400px', margin: 'auto', padding: '20px' }}> |
| 39 | + <h1>Sign Up</h1> |
| 40 | + <input |
| 41 | + 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' }} |
| 46 | + /> |
| 47 | + <input |
| 48 | + type='email' |
| 49 | + placeholder='Email' |
| 50 | + value={email} |
| 51 | + onChange={(e) => setEmail(e.target.value)} |
| 52 | + style={{ display: 'block', width: '100%', marginBottom: '10px', padding: '8px' }} |
| 53 | + /> |
| 54 | + <input |
| 55 | + type='password' |
| 56 | + placeholder='Password' |
| 57 | + value={password} |
| 58 | + onChange={(e) => setPassword(e.target.value)} |
| 59 | + style={{ display: 'block', width: '100%', marginBottom: '10px', padding: '8px' }} |
| 60 | + /> |
| 61 | + <button |
| 62 | + onClick={handleSignUp} |
| 63 | + type='button' |
| 64 | + style={{ |
| 65 | + width: '100%', |
| 66 | + padding: '10px', |
| 67 | + backgroundColor: '#007bff', |
| 68 | + color: 'white', |
| 69 | + border: 'none', |
| 70 | + borderRadius: '5px', |
| 71 | + }} |
| 72 | + > |
| 73 | + Sign Up |
| 74 | + </button> |
| 75 | + {responseMessage && <p style={{ marginTop: '20px', color: 'red' }}>{responseMessage}</p>} |
| 76 | + </div> |
| 77 | + ); |
| 78 | +}; |
| 79 | + |
| 80 | +export default Signup; |
0 commit comments