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/social.js CHANGED
@@ -1,2 +1,586 @@
1
- import"arctic";import{parseJWT as O}from"oslo/jwt";import"@better-fetch/fetch";var d=class extends Error{constructor(i,r,e){super(i),this.name="BetterAuthError",this.message=i,this.cause=r}};import{OAuth2Tokens as x}from"arctic";function k(t){try{return new URL(t).pathname!=="/"}catch{throw new d(`Invalid base URL: ${t}. Please provide a valid base URL.`)}}function f(t,i="/api/auth"){return k(t)?t:(i=i.startsWith("/")?i:`/${i}`,`${t}${i}`)}function g(t,i){if(t)return f(t,i);let r=process?.env||{},e=r.BETTER_AUTH_URL||r.NEXT_PUBLIC_BETTER_AUTH_URL||r.PUBLIC_BETTER_AUTH_URL||r.NUXT_PUBLIC_BETTER_AUTH_URL||r.NUXT_PUBLIC_AUTH_URL||(r.BASE_URL!=="/"?r.BASE_URL:void 0);if(e)return f(e,i);if(typeof window<"u")return f(window.location.origin,i)}import{betterFetch as T}from"@better-fetch/fetch";function n(t,i){return i||`${g()}/callback/${t}`}async function s({code:t,codeVerifier:i,redirectURI:r,options:e,tokenEndpoint:o}){let a=new URLSearchParams;a.set("grant_type","authorization_code"),a.set("code",t),i&&a.set("code_verifier",i),a.set("redirect_uri",r),a.set("client_id",e.clientId),a.set("client_secret",e.clientSecret);let{data:c,error:u}=await T(o,{method:"POST",body:a,headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json","user-agent":"better-auth"}});if(u)throw u;return new x(c)}var h=t=>{let i="https://appleid.apple.com/auth/token";return{id:"apple",name:"Apple",createAuthorizationURL({state:r,scopes:e,redirectURI:o}){let a=e||["email","name","openid"];return new URL(`https://appleid.apple.com/auth/authorize?client_id=${t.clientId}&response_type=code&redirect_uri=${o||t.redirectURI}&scope=${a.join(" ")}&state=${r}`)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("apple",t.redirectURI),options:t,tokenEndpoint:i}),async getUserInfo(r){let e=O(r.idToken())?.payload;return e?{user:{id:e.sub,name:e.name,email:e.email,emailVerified:e.email_verified==="true"},data:e}:null}}};import{betterFetch as L}from"@better-fetch/fetch";import{Discord as z}from"arctic";var b=t=>{let i=new z(t.clientId,t.clientSecret,n("discord",t.redirectURI));return{id:"discord",name:"Discord",createAuthorizationURL({state:r,scopes:e}){let o=e||["email"];return i.createAuthorizationURL(r,o)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("discord",t.redirectURI),options:t,tokenEndpoint:"https://discord.com/api/oauth2/token"}),async getUserInfo(r){let{data:e,error:o}=await L("https://discord.com/api/users/@me",{auth:{type:"Bearer",token:r.accessToken()}});return o?null:{user:{id:e.id,name:e.display_name||e.username||"",email:e.email,emailVerified:e.verified},data:e}}}};import{betterFetch as E}from"@better-fetch/fetch";import{Facebook as S}from"arctic";var _=t=>{let i=new S(t.clientId,t.clientSecret,n("facebook",t.redirectURI));return{id:"facebook",name:"Facebook",createAuthorizationURL({state:r,scopes:e}){let o=e||["email","public_profile"];return i.createAuthorizationURL(r,o)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("facebook",t.redirectURI),options:t,tokenEndpoint:"https://graph.facebook.com/v16.0/oauth/access_token"}),async getUserInfo(r){let{data:e,error:o}=await E("https://graph.facebook.com/me",{auth:{type:"Bearer",token:r.accessToken()}});return o?null:{user:{id:e.id,name:e.name,email:e.email,emailVerified:e.email_verified},data:e}}}};import{betterFetch as A}from"@better-fetch/fetch";import{GitHub as C}from"arctic";var y=({clientId:t,clientSecret:i,redirectURI:r})=>{let e=new C(t,i,n("github",r));return{id:"github",name:"Github",createAuthorizationURL({state:o,scopes:a}){let c=a||["user:email"];return e.createAuthorizationURL(o,c)},validateAuthorizationCode:async o=>await e.validateAuthorizationCode(o),async getUserInfo(o){let{data:a,error:c}=await A("https://api.github.com/user",{auth:{type:"Bearer",token:o.accessToken()}});if(c)return null;let u=!1;if(!a.email){let{data:m,error:P}=await A("https://api.github.com/user/emails",{auth:{type:"Bearer",token:o.accessToken()}});P||(a.email=(m.find(p=>p.primary)??m[0])?.email,u=m.find(p=>p.email===a.email)?.verified??!1)}return{user:{id:a.id,name:a.name,email:a.email,image:a.avatar_url,emailVerified:u,createdAt:new Date,updatedAt:new Date},data:a}}}};import{Google as F}from"arctic";import{parseJWT as V}from"oslo/jwt";import{createConsola as B}from"consola";var l=B({formatOptions:{date:!1,colors:!0,compact:!0},defaults:{tag:"Better Auth"}}),G=t=>({log:(...i)=>{!t?.disabled&&l.log("",...i)},error:(...i)=>{!t?.disabled&&l.error("",...i)},warn:(...i)=>{!t?.disabled&&l.warn("",...i)},info:(...i)=>{!t?.disabled&&l.info("",...i)},debug:(...i)=>{!t?.disabled&&l.debug("",...i)},box:(...i)=>{!t?.disabled&&l.box("",...i)},success:(...i)=>{!t?.disabled&&l.success("",...i)},break:(...i)=>{!t?.disabled&&console.log(`
2
- `)}}),U=G();var v=t=>{let i=new F(t.clientId,t.clientSecret,n("google",t.redirectURI));return{id:"google",name:"Google",createAuthorizationURL({state:r,scopes:e,codeVerifier:o,redirectURI:a}){if(!t.clientId||!t.clientSecret)throw U.error("Client Id and Client Secret is required for Google. Make sure to provide them in the options."),new d("CLIENT_ID_AND_SECRET_REQUIRED");if(!o)throw new d("codeVerifier is required for Google");let c=e||["email","profile"];return i.createAuthorizationURL(r,o,c)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("google",t.redirectURI),options:t,tokenEndpoint:"https://oauth2.googleapis.com/token"}),async getUserInfo(r){if(!r.idToken)return null;let e=V(r.idToken())?.payload;return{user:{id:e.sub,name:e.name,email:e.email,image:e.picture,emailVerified:e.email_verified},data:e}}}};import{betterFetch as $}from"@better-fetch/fetch";import{Spotify as D}from"arctic";var R=t=>{let i=new D(t.clientId,t.clientSecret,n("spotify",t.redirectURI));return{id:"spotify",name:"Spotify",createAuthorizationURL({state:r,scopes:e}){let o=e||["user-read-email"];return i.createAuthorizationURL(r,o)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("spotify",t.redirectURI),options:t,tokenEndpoint:"https://accounts.spotify.com/api/token"}),async getUserInfo(r){let{data:e,error:o}=await $("https://api.spotify.com/v1/me",{method:"GET",headers:{Authorization:`Bearer ${r.accessToken()}`}});return o?null:{user:{id:e.id,name:e.display_name,email:e.email,image:e.images[0]?.url,emailVerified:!1},data:e}}}};import{betterFetch as H}from"@better-fetch/fetch";import{Twitch as j}from"arctic";var w=t=>{let i=new j(t.clientId,t.clientSecret,n("twitch",t.redirectURI));return{id:"twitch",name:"Twitch",createAuthorizationURL({state:r,scopes:e}){let o=e||["activity:write","read"];return i.createAuthorizationURL(r,o)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("twitch",t.redirectURI),options:t,tokenEndpoint:"https://id.twitch.tv/oauth2/token"}),async getUserInfo(r){let{data:e,error:o}=await H("https://api.twitch.tv/helix/users",{method:"GET",headers:{Authorization:`Bearer ${r.accessToken()}`}});return o?null:{user:{id:e.sub,name:e.preferred_username,email:e.email,image:e.picture,emailVerified:!1},data:e}}}};import{betterFetch as N}from"@better-fetch/fetch";import{Twitter as W}from"arctic";var I=t=>{let i=new W(t.clientId,t.clientSecret,n("twitter",t.redirectURI));return{id:"twitter",name:"Twitter",createAuthorizationURL(r){let e=r.scopes||["account_info.read"];return i.createAuthorizationURL(r.state,r.codeVerifier,e)},validateAuthorizationCode:async(r,e,o)=>s({code:r,codeVerifier:e,redirectURI:o||n("twitch",t.redirectURI),options:t,tokenEndpoint:"https://id.twitch.tv/oauth2/token"}),async getUserInfo(r){let{data:e,error:o}=await N("https://api.x.com/2/users/me?user.fields=profile_image_url",{method:"GET",headers:{Authorization:`Bearer ${r.accessToken()}`}});return o||!e.data.email?null:{user:{id:e.data.id,name:e.data.name,email:e.data.email,image:e.data.profile_image_url,emailVerified:e.data.verified||!1},data:e}}}};import"arctic";var X={apple:h,discord:b,facebook:_,github:y,google:v,spotify:R,twitch:w,twitter:I},Ze=Object.keys(X);export{h as apple,b as discord,_ as facebook,y as github,v as google,Ze as oAuthProviderList,X as oAuthProviders,R as spotify,w as twitch,I as twitter};
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
+ };
@@ -1 +1,13 @@
1
- function n(r){let e=async t=>"handler"in r?r.handler(t.request):r(t.request);return{GET:e,POST:e}}export{n as toSolidStartHandler};
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
+ };