-
Notifications
You must be signed in to change notification settings - Fork 516
Expand file tree
/
Copy pathcustomization.ts
More file actions
207 lines (185 loc) · 6.17 KB
/
customization.ts
File metadata and controls
207 lines (185 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { CodeExample } from '../lib/code-examples';
export const customizationExamples = {
'sign-in': {
'default': [
{
language: 'JavaScript',
framework: 'Next.js',
code: `'use client';
import { SignIn } from "@stackframe/stack";
export default function DefaultSignIn() {
// optionally redirect to some other page if the user is already signed in
// const user = useUser();
// if (user) { redirect to some other page }
return <SignIn fullPage />;
}`,
highlightLanguage: 'tsx',
filename: 'app/handler/sign-in/page.tsx',
},
] as CodeExample[],
'custom-oauth': [
{
language: 'JavaScript',
framework: 'Next.js',
code: `'use client';
import { useStackApp } from "@stackframe/stack";
export default function CustomOAuthSignIn() {
const app = useStackApp();
return (
<div>
<h1>My Custom Sign In page</h1>
<button onClick={async () => {
// This will redirect to the OAuth provider's login page.
await app.signInWithOAuth('google');
}}>
Sign In with Google
</button>
</div>
);
}`,
highlightLanguage: 'tsx',
filename: 'app/handler/sign-in/page.tsx',
},
] as CodeExample[],
'custom-credential': [
{
language: 'JavaScript',
framework: 'Next.js',
code: `'use client';
import { useStackApp } from "@stackframe/stack";
import { useState } from "react";
export default function CustomCredentialSignIn() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const app = useStackApp();
const onSubmit = async () => {
if (!password) {
setError('Please enter your password');
return;
}
// This will redirect to app.urls.afterSignIn if successful.
// You can customize the redirect URL in the StackServerApp constructor.
const result = await app.signInWithCredential({ email, password });
// It's better to handle each error code separately, but for simplicity,
// we'll just display the error message directly here.
if (result.status === 'error') {
setError(result.error.message);
}
};
return (
<form onSubmit={(e) => { e.preventDefault(); onSubmit(); } }>
{error}
<input type='email' placeholder="email@example.com" value={email} onChange={(e) => setEmail(e.target.value)} />
<input type='password' placeholder="password" value={password} onChange={(e) => setPassword(e.target.value)} />
<button type='submit'>Sign In</button>
</form>
);
}`,
highlightLanguage: 'tsx',
filename: 'app/handler/sign-in/page.tsx',
},
] as CodeExample[],
'custom-magic-link': [
{
language: 'JavaScript',
framework: 'Next.js',
code: `'use client';
import { useStackApp } from "@stackframe/stack";
import { useState } from "react";
export default function CustomMagicLinkSignIn() {
const [email, setEmail] = useState('');
const [error, setError] = useState('');
const [message, setMessage] = useState('');
const app = useStackApp();
const onSubmit = async () => {
if (!email) {
setError('Please enter your email address');
return;
}
// This will send a magic link email to the user's email address.
// When they click the link, they will be redirected to your application.
const result = await app.sendMagicLinkEmail(email);
// It's better to handle each error code separately, but for simplicity,
// we'll just display the error message directly here.
if (result.status === 'error') {
setError(result.error.message);
} else {
setMessage('Magic link sent! Please check your email.');
}
};
return (
<form onSubmit={(e) => { e.preventDefault(); onSubmit(); } }>
{error}
{message ?
<div>{message}</div> :
<>
<input type='email' placeholder="email@example.com" value={email} onChange={(e) => setEmail(e.target.value)} />
<button type='submit'>Send Magic Link</button>
</>}
</form>
);
}`,
highlightLanguage: 'tsx',
filename: 'app/handler/sign-in/page.tsx',
},
] as CodeExample[],
},
'sign-up': {
'default': [
{
language: 'JavaScript',
framework: 'Next.js',
code: `'use client';
import { SignUp } from "@stackframe/stack";
export default function DefaultSignUp() {
// optionally redirect to some other page if the user is already signed in
// const user = useUser();
// if (user) { redirect to some other page }
return <SignUp fullPage />;
}`,
highlightLanguage: 'tsx',
filename: 'app/handler/sign-up/page.tsx',
},
] as CodeExample[],
'custom-credential': [
{
language: 'JavaScript',
framework: 'Next.js',
code: `'use client';
import { useStackApp } from "@stackframe/stack";
import { useState } from "react";
export default function CustomCredentialSignUp() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const app = useStackApp();
const onSubmit = async () => {
if (!password) {
setError('Please enter your password');
return;
}
// This will redirect to app.urls.afterSignUp if successful.
// You can customize the redirect URL in the StackServerApp constructor.
const result = await app.signUpWithCredential({ email, password });
// It's better to handle each error code separately, but for simplicity,
// we'll just display the error message directly here.
if (result.status === 'error') {
setError(result.error.message);
}
};
return (
<form onSubmit={(e) => { e.preventDefault(); onSubmit(); } }>
{error}
<input type='email' placeholder="email@example.com" value={email} onChange={(e) => setEmail(e.target.value)} />
<input type='password' placeholder="password" value={password} onChange={(e) => setPassword(e.target.value)} />
<button type='submit'>Sign Up</button>
</form>
);
}`,
highlightLanguage: 'tsx',
filename: 'app/handler/sign-up/page.tsx',
},
] as CodeExample[],
},
};