better-auth 0.2.3-beta.8 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access.js +125 -1
- package/dist/adapters.d.ts +1 -2
- package/dist/adapters.js +1155 -14
- package/dist/api.js +2458 -4
- package/dist/cli.js +1010 -3
- package/dist/client/plugins.js +527 -2
- package/dist/client.js +382 -1
- package/dist/index.js +3670 -5
- package/dist/next-js.js +34 -1
- package/dist/node.js +8 -1
- package/dist/plugins.js +5529 -4
- package/dist/react.js +393 -1
- package/dist/social.js +586 -2
- package/dist/solid-start.js +13 -1
- package/dist/solid.js +389 -1
- package/dist/svelte-kit.js +34 -1
- package/dist/svelte.js +380 -1
- package/dist/utils.js +453 -2
- package/dist/vue.js +389 -1
- package/package.json +5 -3
package/dist/social.js
CHANGED
|
@@ -1,2 +1,586 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/social-providers/apple.ts
|
|
2
|
+
import "arctic";
|
|
3
|
+
import { parseJWT } from "oslo/jwt";
|
|
4
|
+
import "@better-fetch/fetch";
|
|
5
|
+
|
|
6
|
+
// src/error/better-auth-error.ts
|
|
7
|
+
var BetterAuthError = class extends Error {
|
|
8
|
+
constructor(message, cause, docsLink) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "BetterAuthError";
|
|
11
|
+
this.message = message;
|
|
12
|
+
this.cause = cause;
|
|
13
|
+
this.stack = "";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/social-providers/utils.ts
|
|
18
|
+
import { OAuth2Tokens } from "arctic";
|
|
19
|
+
|
|
20
|
+
// src/utils/base-url.ts
|
|
21
|
+
function checkHasPath(url) {
|
|
22
|
+
try {
|
|
23
|
+
const parsedUrl = new URL(url);
|
|
24
|
+
return parsedUrl.pathname !== "/";
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new BetterAuthError(
|
|
27
|
+
`Invalid base URL: ${url}. Please provide a valid base URL.`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function withPath(url, path = "/api/auth") {
|
|
32
|
+
const hasPath = checkHasPath(url);
|
|
33
|
+
if (hasPath) {
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
path = path.startsWith("/") ? path : `/${path}`;
|
|
37
|
+
return `${url}${path}`;
|
|
38
|
+
}
|
|
39
|
+
function getBaseURL(url, path) {
|
|
40
|
+
if (url) {
|
|
41
|
+
return withPath(url, path);
|
|
42
|
+
}
|
|
43
|
+
const env = process?.env || {};
|
|
44
|
+
const fromEnv = env.BETTER_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL || (env.BASE_URL !== "/" ? env.BASE_URL : void 0);
|
|
45
|
+
if (fromEnv) {
|
|
46
|
+
return withPath(fromEnv, path);
|
|
47
|
+
}
|
|
48
|
+
if (typeof window !== "undefined") {
|
|
49
|
+
return withPath(window.location.origin, path);
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/social-providers/utils.ts
|
|
55
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
56
|
+
function getRedirectURI(providerId, redirectURI) {
|
|
57
|
+
return redirectURI || `${getBaseURL()}/callback/${providerId}`;
|
|
58
|
+
}
|
|
59
|
+
async function validateAuthorizationCode({
|
|
60
|
+
code,
|
|
61
|
+
codeVerifier,
|
|
62
|
+
redirectURI,
|
|
63
|
+
options,
|
|
64
|
+
tokenEndpoint
|
|
65
|
+
}) {
|
|
66
|
+
const body = new URLSearchParams();
|
|
67
|
+
body.set("grant_type", "authorization_code");
|
|
68
|
+
body.set("code", code);
|
|
69
|
+
codeVerifier && body.set("code_verifier", codeVerifier);
|
|
70
|
+
body.set("redirect_uri", redirectURI);
|
|
71
|
+
body.set("client_id", options.clientId);
|
|
72
|
+
body.set("client_secret", options.clientSecret);
|
|
73
|
+
const { data, error } = await betterFetch(tokenEndpoint, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body,
|
|
76
|
+
headers: {
|
|
77
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
78
|
+
accept: "application/json",
|
|
79
|
+
"user-agent": "better-auth"
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (error) {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
const tokens = new OAuth2Tokens(data);
|
|
86
|
+
return tokens;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/social-providers/apple.ts
|
|
90
|
+
var apple = (options) => {
|
|
91
|
+
const tokenEndpoint = "https://appleid.apple.com/auth/token";
|
|
92
|
+
return {
|
|
93
|
+
id: "apple",
|
|
94
|
+
name: "Apple",
|
|
95
|
+
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
96
|
+
const _scope = scopes || ["email", "name", "openid"];
|
|
97
|
+
return new URL(
|
|
98
|
+
`https://appleid.apple.com/auth/authorize?client_id=${options.clientId}&response_type=code&redirect_uri=${redirectURI || options.redirectURI}&scope=${_scope.join(" ")}&state=${state}`
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
102
|
+
return validateAuthorizationCode({
|
|
103
|
+
code,
|
|
104
|
+
codeVerifier,
|
|
105
|
+
redirectURI: redirectURI || getRedirectURI("apple", options.redirectURI),
|
|
106
|
+
options,
|
|
107
|
+
tokenEndpoint
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
async getUserInfo(token) {
|
|
111
|
+
const data = parseJWT(token.idToken())?.payload;
|
|
112
|
+
if (!data) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
user: {
|
|
117
|
+
id: data.sub,
|
|
118
|
+
name: data.name,
|
|
119
|
+
email: data.email,
|
|
120
|
+
emailVerified: data.email_verified === "true"
|
|
121
|
+
},
|
|
122
|
+
data
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/social-providers/discord.ts
|
|
129
|
+
import { betterFetch as betterFetch3 } from "@better-fetch/fetch";
|
|
130
|
+
import { Discord } from "arctic";
|
|
131
|
+
var discord = (options) => {
|
|
132
|
+
const discordArctic = new Discord(
|
|
133
|
+
options.clientId,
|
|
134
|
+
options.clientSecret,
|
|
135
|
+
getRedirectURI("discord", options.redirectURI)
|
|
136
|
+
);
|
|
137
|
+
return {
|
|
138
|
+
id: "discord",
|
|
139
|
+
name: "Discord",
|
|
140
|
+
createAuthorizationURL({ state, scopes }) {
|
|
141
|
+
const _scope = scopes || ["email"];
|
|
142
|
+
return discordArctic.createAuthorizationURL(state, _scope);
|
|
143
|
+
},
|
|
144
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
145
|
+
return validateAuthorizationCode({
|
|
146
|
+
code,
|
|
147
|
+
codeVerifier,
|
|
148
|
+
redirectURI: redirectURI || getRedirectURI("discord", options.redirectURI),
|
|
149
|
+
options,
|
|
150
|
+
tokenEndpoint: "https://discord.com/api/oauth2/token"
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
async getUserInfo(token) {
|
|
154
|
+
const { data: profile, error } = await betterFetch3(
|
|
155
|
+
"https://discord.com/api/users/@me",
|
|
156
|
+
{
|
|
157
|
+
auth: {
|
|
158
|
+
type: "Bearer",
|
|
159
|
+
token: token.accessToken()
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
if (error) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
user: {
|
|
168
|
+
id: profile.id,
|
|
169
|
+
name: profile.display_name || profile.username || "",
|
|
170
|
+
email: profile.email,
|
|
171
|
+
emailVerified: profile.verified
|
|
172
|
+
},
|
|
173
|
+
data: profile
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/social-providers/facebook.ts
|
|
180
|
+
import { betterFetch as betterFetch4 } from "@better-fetch/fetch";
|
|
181
|
+
import { Facebook } from "arctic";
|
|
182
|
+
var facebook = (options) => {
|
|
183
|
+
const facebookArctic = new Facebook(
|
|
184
|
+
options.clientId,
|
|
185
|
+
options.clientSecret,
|
|
186
|
+
getRedirectURI("facebook", options.redirectURI)
|
|
187
|
+
);
|
|
188
|
+
return {
|
|
189
|
+
id: "facebook",
|
|
190
|
+
name: "Facebook",
|
|
191
|
+
createAuthorizationURL({ state, scopes }) {
|
|
192
|
+
const _scopes = scopes || ["email", "public_profile"];
|
|
193
|
+
return facebookArctic.createAuthorizationURL(state, _scopes);
|
|
194
|
+
},
|
|
195
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
196
|
+
return validateAuthorizationCode({
|
|
197
|
+
code,
|
|
198
|
+
codeVerifier,
|
|
199
|
+
redirectURI: redirectURI || getRedirectURI("facebook", options.redirectURI),
|
|
200
|
+
options,
|
|
201
|
+
tokenEndpoint: "https://graph.facebook.com/v16.0/oauth/access_token"
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
async getUserInfo(token) {
|
|
205
|
+
const { data: profile, error } = await betterFetch4(
|
|
206
|
+
"https://graph.facebook.com/me",
|
|
207
|
+
{
|
|
208
|
+
auth: {
|
|
209
|
+
type: "Bearer",
|
|
210
|
+
token: token.accessToken()
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
if (error) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
user: {
|
|
219
|
+
id: profile.id,
|
|
220
|
+
name: profile.name,
|
|
221
|
+
email: profile.email,
|
|
222
|
+
emailVerified: profile.email_verified
|
|
223
|
+
},
|
|
224
|
+
data: profile
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/social-providers/github.ts
|
|
231
|
+
import { betterFetch as betterFetch5 } from "@better-fetch/fetch";
|
|
232
|
+
import { GitHub } from "arctic";
|
|
233
|
+
var github = ({
|
|
234
|
+
clientId,
|
|
235
|
+
clientSecret,
|
|
236
|
+
redirectURI
|
|
237
|
+
}) => {
|
|
238
|
+
const githubArctic = new GitHub(
|
|
239
|
+
clientId,
|
|
240
|
+
clientSecret,
|
|
241
|
+
getRedirectURI("github", redirectURI)
|
|
242
|
+
);
|
|
243
|
+
return {
|
|
244
|
+
id: "github",
|
|
245
|
+
name: "Github",
|
|
246
|
+
createAuthorizationURL({ state, scopes }) {
|
|
247
|
+
const _scopes = scopes || ["user:email"];
|
|
248
|
+
return githubArctic.createAuthorizationURL(state, _scopes);
|
|
249
|
+
},
|
|
250
|
+
validateAuthorizationCode: async (state) => {
|
|
251
|
+
return await githubArctic.validateAuthorizationCode(state);
|
|
252
|
+
},
|
|
253
|
+
async getUserInfo(token) {
|
|
254
|
+
const { data: profile, error } = await betterFetch5(
|
|
255
|
+
"https://api.github.com/user",
|
|
256
|
+
{
|
|
257
|
+
auth: {
|
|
258
|
+
type: "Bearer",
|
|
259
|
+
token: token.accessToken()
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
if (error) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
let emailVerified = false;
|
|
267
|
+
if (!profile.email) {
|
|
268
|
+
const { data, error: error2 } = await betterFetch5("https://api.github.com/user/emails", {
|
|
269
|
+
auth: {
|
|
270
|
+
type: "Bearer",
|
|
271
|
+
token: token.accessToken()
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
if (!error2) {
|
|
275
|
+
profile.email = (data.find((e) => e.primary) ?? data[0])?.email;
|
|
276
|
+
emailVerified = data.find((e) => e.email === profile.email)?.verified ?? false;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
user: {
|
|
281
|
+
id: profile.id,
|
|
282
|
+
name: profile.name,
|
|
283
|
+
email: profile.email,
|
|
284
|
+
image: profile.avatar_url,
|
|
285
|
+
emailVerified,
|
|
286
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
287
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
288
|
+
},
|
|
289
|
+
data: profile
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/social-providers/google.ts
|
|
296
|
+
import { Google } from "arctic";
|
|
297
|
+
import { parseJWT as parseJWT2 } from "oslo/jwt";
|
|
298
|
+
|
|
299
|
+
// src/utils/logger.ts
|
|
300
|
+
import { createConsola } from "consola";
|
|
301
|
+
var consola = createConsola({
|
|
302
|
+
formatOptions: {
|
|
303
|
+
date: false,
|
|
304
|
+
colors: true,
|
|
305
|
+
compact: true
|
|
306
|
+
},
|
|
307
|
+
defaults: {
|
|
308
|
+
tag: "Better Auth"
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
var createLogger = (options) => {
|
|
312
|
+
return {
|
|
313
|
+
log: (...args) => {
|
|
314
|
+
!options?.disabled && consola.log("", ...args);
|
|
315
|
+
},
|
|
316
|
+
error: (...args) => {
|
|
317
|
+
!options?.disabled && consola.error("", ...args);
|
|
318
|
+
},
|
|
319
|
+
warn: (...args) => {
|
|
320
|
+
!options?.disabled && consola.warn("", ...args);
|
|
321
|
+
},
|
|
322
|
+
info: (...args) => {
|
|
323
|
+
!options?.disabled && consola.info("", ...args);
|
|
324
|
+
},
|
|
325
|
+
debug: (...args) => {
|
|
326
|
+
!options?.disabled && consola.debug("", ...args);
|
|
327
|
+
},
|
|
328
|
+
box: (...args) => {
|
|
329
|
+
!options?.disabled && consola.box("", ...args);
|
|
330
|
+
},
|
|
331
|
+
success: (...args) => {
|
|
332
|
+
!options?.disabled && consola.success("", ...args);
|
|
333
|
+
},
|
|
334
|
+
break: (...args) => {
|
|
335
|
+
!options?.disabled && console.log("\n");
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
var logger = createLogger();
|
|
340
|
+
|
|
341
|
+
// src/social-providers/google.ts
|
|
342
|
+
var google = (options) => {
|
|
343
|
+
const googleArctic = new Google(
|
|
344
|
+
options.clientId,
|
|
345
|
+
options.clientSecret,
|
|
346
|
+
getRedirectURI("google", options.redirectURI)
|
|
347
|
+
);
|
|
348
|
+
return {
|
|
349
|
+
id: "google",
|
|
350
|
+
name: "Google",
|
|
351
|
+
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
352
|
+
if (!options.clientId || !options.clientSecret) {
|
|
353
|
+
logger.error(
|
|
354
|
+
"Client Id and Client Secret is required for Google. Make sure to provide them in the options."
|
|
355
|
+
);
|
|
356
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
357
|
+
}
|
|
358
|
+
if (!codeVerifier) {
|
|
359
|
+
throw new BetterAuthError("codeVerifier is required for Google");
|
|
360
|
+
}
|
|
361
|
+
const _scopes = scopes || ["email", "profile"];
|
|
362
|
+
const url = googleArctic.createAuthorizationURL(
|
|
363
|
+
state,
|
|
364
|
+
codeVerifier,
|
|
365
|
+
_scopes
|
|
366
|
+
);
|
|
367
|
+
return url;
|
|
368
|
+
},
|
|
369
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
370
|
+
return validateAuthorizationCode({
|
|
371
|
+
code,
|
|
372
|
+
codeVerifier,
|
|
373
|
+
redirectURI: redirectURI || getRedirectURI("google", options.redirectURI),
|
|
374
|
+
options,
|
|
375
|
+
tokenEndpoint: "https://oauth2.googleapis.com/token"
|
|
376
|
+
});
|
|
377
|
+
},
|
|
378
|
+
async getUserInfo(token) {
|
|
379
|
+
if (!token.idToken) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
const user = parseJWT2(token.idToken())?.payload;
|
|
383
|
+
return {
|
|
384
|
+
user: {
|
|
385
|
+
id: user.sub,
|
|
386
|
+
name: user.name,
|
|
387
|
+
email: user.email,
|
|
388
|
+
image: user.picture,
|
|
389
|
+
emailVerified: user.email_verified
|
|
390
|
+
},
|
|
391
|
+
data: user
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// src/social-providers/spotify.ts
|
|
398
|
+
import { betterFetch as betterFetch6 } from "@better-fetch/fetch";
|
|
399
|
+
import { Spotify } from "arctic";
|
|
400
|
+
var spotify = (options) => {
|
|
401
|
+
const spotifyArctic = new Spotify(
|
|
402
|
+
options.clientId,
|
|
403
|
+
options.clientSecret,
|
|
404
|
+
getRedirectURI("spotify", options.redirectURI)
|
|
405
|
+
);
|
|
406
|
+
return {
|
|
407
|
+
id: "spotify",
|
|
408
|
+
name: "Spotify",
|
|
409
|
+
createAuthorizationURL({ state, scopes }) {
|
|
410
|
+
const _scopes = scopes || ["user-read-email"];
|
|
411
|
+
return spotifyArctic.createAuthorizationURL(state, _scopes);
|
|
412
|
+
},
|
|
413
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
414
|
+
return validateAuthorizationCode({
|
|
415
|
+
code,
|
|
416
|
+
codeVerifier,
|
|
417
|
+
redirectURI: redirectURI || getRedirectURI("spotify", options.redirectURI),
|
|
418
|
+
options,
|
|
419
|
+
tokenEndpoint: "https://accounts.spotify.com/api/token"
|
|
420
|
+
});
|
|
421
|
+
},
|
|
422
|
+
async getUserInfo(token) {
|
|
423
|
+
const { data: profile, error } = await betterFetch6(
|
|
424
|
+
"https://api.spotify.com/v1/me",
|
|
425
|
+
{
|
|
426
|
+
method: "GET",
|
|
427
|
+
headers: {
|
|
428
|
+
Authorization: `Bearer ${token.accessToken()}`
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
);
|
|
432
|
+
if (error) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
user: {
|
|
437
|
+
id: profile.id,
|
|
438
|
+
name: profile.display_name,
|
|
439
|
+
email: profile.email,
|
|
440
|
+
image: profile.images[0]?.url,
|
|
441
|
+
emailVerified: false
|
|
442
|
+
},
|
|
443
|
+
data: profile
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// src/social-providers/twitch.ts
|
|
450
|
+
import { betterFetch as betterFetch7 } from "@better-fetch/fetch";
|
|
451
|
+
import { Twitch } from "arctic";
|
|
452
|
+
var twitch = (options) => {
|
|
453
|
+
const twitchArctic = new Twitch(
|
|
454
|
+
options.clientId,
|
|
455
|
+
options.clientSecret,
|
|
456
|
+
getRedirectURI("twitch", options.redirectURI)
|
|
457
|
+
);
|
|
458
|
+
return {
|
|
459
|
+
id: "twitch",
|
|
460
|
+
name: "Twitch",
|
|
461
|
+
createAuthorizationURL({ state, scopes }) {
|
|
462
|
+
const _scopes = scopes || ["activity:write", "read"];
|
|
463
|
+
return twitchArctic.createAuthorizationURL(state, _scopes);
|
|
464
|
+
},
|
|
465
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
466
|
+
return validateAuthorizationCode({
|
|
467
|
+
code,
|
|
468
|
+
codeVerifier,
|
|
469
|
+
redirectURI: redirectURI || getRedirectURI("twitch", options.redirectURI),
|
|
470
|
+
options,
|
|
471
|
+
tokenEndpoint: "https://id.twitch.tv/oauth2/token"
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
async getUserInfo(token) {
|
|
475
|
+
const { data: profile, error } = await betterFetch7(
|
|
476
|
+
"https://api.twitch.tv/helix/users",
|
|
477
|
+
{
|
|
478
|
+
method: "GET",
|
|
479
|
+
headers: {
|
|
480
|
+
Authorization: `Bearer ${token.accessToken()}`
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
if (error) {
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
user: {
|
|
489
|
+
id: profile.sub,
|
|
490
|
+
name: profile.preferred_username,
|
|
491
|
+
email: profile.email,
|
|
492
|
+
image: profile.picture,
|
|
493
|
+
emailVerified: false
|
|
494
|
+
},
|
|
495
|
+
data: profile
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/social-providers/twitter.ts
|
|
502
|
+
import { betterFetch as betterFetch8 } from "@better-fetch/fetch";
|
|
503
|
+
import { Twitter } from "arctic";
|
|
504
|
+
var twitter = (options) => {
|
|
505
|
+
const twitterArctic = new Twitter(
|
|
506
|
+
options.clientId,
|
|
507
|
+
options.clientSecret,
|
|
508
|
+
getRedirectURI("twitter", options.redirectURI)
|
|
509
|
+
);
|
|
510
|
+
return {
|
|
511
|
+
id: "twitter",
|
|
512
|
+
name: "Twitter",
|
|
513
|
+
createAuthorizationURL(data) {
|
|
514
|
+
const _scopes = data.scopes || ["account_info.read"];
|
|
515
|
+
return twitterArctic.createAuthorizationURL(
|
|
516
|
+
data.state,
|
|
517
|
+
data.codeVerifier,
|
|
518
|
+
_scopes
|
|
519
|
+
);
|
|
520
|
+
},
|
|
521
|
+
validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
|
|
522
|
+
return validateAuthorizationCode({
|
|
523
|
+
code,
|
|
524
|
+
codeVerifier,
|
|
525
|
+
redirectURI: redirectURI || getRedirectURI("twitch", options.redirectURI),
|
|
526
|
+
options,
|
|
527
|
+
tokenEndpoint: "https://id.twitch.tv/oauth2/token"
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
async getUserInfo(token) {
|
|
531
|
+
const { data: profile, error } = await betterFetch8(
|
|
532
|
+
"https://api.x.com/2/users/me?user.fields=profile_image_url",
|
|
533
|
+
{
|
|
534
|
+
method: "GET",
|
|
535
|
+
headers: {
|
|
536
|
+
Authorization: `Bearer ${token.accessToken()}`
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
if (error) {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
if (!profile.data.email) {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
return {
|
|
547
|
+
user: {
|
|
548
|
+
id: profile.data.id,
|
|
549
|
+
name: profile.data.name,
|
|
550
|
+
email: profile.data.email,
|
|
551
|
+
image: profile.data.profile_image_url,
|
|
552
|
+
emailVerified: profile.data.verified || false
|
|
553
|
+
},
|
|
554
|
+
data: profile
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// src/types/provider.ts
|
|
561
|
+
import "arctic";
|
|
562
|
+
|
|
563
|
+
// src/social-providers/index.ts
|
|
564
|
+
var oAuthProviders = {
|
|
565
|
+
apple,
|
|
566
|
+
discord,
|
|
567
|
+
facebook,
|
|
568
|
+
github,
|
|
569
|
+
google,
|
|
570
|
+
spotify,
|
|
571
|
+
twitch,
|
|
572
|
+
twitter
|
|
573
|
+
};
|
|
574
|
+
var oAuthProviderList = Object.keys(oAuthProviders);
|
|
575
|
+
export {
|
|
576
|
+
apple,
|
|
577
|
+
discord,
|
|
578
|
+
facebook,
|
|
579
|
+
github,
|
|
580
|
+
google,
|
|
581
|
+
oAuthProviderList,
|
|
582
|
+
oAuthProviders,
|
|
583
|
+
spotify,
|
|
584
|
+
twitch,
|
|
585
|
+
twitter
|
|
586
|
+
};
|
package/dist/solid-start.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// src/integrations/solid-start.ts
|
|
2
|
+
function toSolidStartHandler(auth) {
|
|
3
|
+
const handler = async (event) => {
|
|
4
|
+
return "handler" in auth ? auth.handler(event.request) : auth(event.request);
|
|
5
|
+
};
|
|
6
|
+
return {
|
|
7
|
+
GET: handler,
|
|
8
|
+
POST: handler
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
toSolidStartHandler
|
|
13
|
+
};
|