@fastshot/auth 1.0.1 → 1.0.2

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.
Files changed (47) hide show
  1. package/package.json +3 -4
  2. package/src/auth.ts +210 -0
  3. package/src/constants.ts +56 -0
  4. package/{dist/hooks/index.d.ts → src/hooks/index.ts} +2 -1
  5. package/src/hooks/useAppleSignIn.ts +92 -0
  6. package/src/hooks/useAuthCallback.ts +135 -0
  7. package/src/hooks/useGoogleSignIn.ts +95 -0
  8. package/{dist/index.js → src/index.ts} +42 -3
  9. package/src/types.ts +109 -0
  10. package/src/utils/deepLink.ts +76 -0
  11. package/src/utils/index.ts +14 -0
  12. package/src/utils/session.ts +45 -0
  13. package/src/utils/ticketExchange.ts +84 -0
  14. package/dist/auth.d.ts +0 -82
  15. package/dist/auth.d.ts.map +0 -1
  16. package/dist/auth.js +0 -149
  17. package/dist/constants.d.ts +0 -38
  18. package/dist/constants.d.ts.map +0 -1
  19. package/dist/constants.js +0 -48
  20. package/dist/hooks/index.d.ts.map +0 -1
  21. package/dist/hooks/index.js +0 -3
  22. package/dist/hooks/useAppleSignIn.d.ts +0 -47
  23. package/dist/hooks/useAppleSignIn.d.ts.map +0 -1
  24. package/dist/hooks/useAppleSignIn.js +0 -60
  25. package/dist/hooks/useAuthCallback.d.ts +0 -56
  26. package/dist/hooks/useAuthCallback.d.ts.map +0 -1
  27. package/dist/hooks/useAuthCallback.js +0 -97
  28. package/dist/hooks/useGoogleSignIn.d.ts +0 -49
  29. package/dist/hooks/useGoogleSignIn.d.ts.map +0 -1
  30. package/dist/hooks/useGoogleSignIn.js +0 -61
  31. package/dist/index.d.ts +0 -61
  32. package/dist/index.d.ts.map +0 -1
  33. package/dist/types.d.ts +0 -95
  34. package/dist/types.d.ts.map +0 -1
  35. package/dist/types.js +0 -1
  36. package/dist/utils/deepLink.d.ts +0 -26
  37. package/dist/utils/deepLink.d.ts.map +0 -1
  38. package/dist/utils/deepLink.js +0 -55
  39. package/dist/utils/index.d.ts +0 -4
  40. package/dist/utils/index.d.ts.map +0 -1
  41. package/dist/utils/index.js +0 -3
  42. package/dist/utils/session.d.ts +0 -7
  43. package/dist/utils/session.d.ts.map +0 -1
  44. package/dist/utils/session.js +0 -25
  45. package/dist/utils/ticketExchange.d.ts +0 -14
  46. package/dist/utils/ticketExchange.d.ts.map +0 -1
  47. package/dist/utils/ticketExchange.js +0 -54
@@ -1,25 +0,0 @@
1
- import { createAuthError } from './ticketExchange';
2
- /**
3
- * Restore a Supabase session from exchange response
4
- */
5
- export async function restoreSession(supabaseClient, exchangeResponse) {
6
- try {
7
- const { data, error } = await supabaseClient.auth.setSession({
8
- access_token: exchangeResponse.access_token,
9
- refresh_token: exchangeResponse.refresh_token,
10
- });
11
- if (error) {
12
- throw createAuthError('SESSION_RESTORE_FAILED', `Failed to restore session: ${error.message}`, error);
13
- }
14
- if (!data.session) {
15
- throw createAuthError('SESSION_RESTORE_FAILED', 'Session restore succeeded but no session returned');
16
- }
17
- return data.session;
18
- }
19
- catch (error) {
20
- if (error.type) {
21
- throw error;
22
- }
23
- throw createAuthError('SESSION_RESTORE_FAILED', error instanceof Error ? error.message : 'Unknown error during session restore', error);
24
- }
25
- }
@@ -1,14 +0,0 @@
1
- import type { ExchangeTicketResponse, AuthError } from '../types';
2
- /**
3
- * Exchange a one-time ticket for Supabase session tokens
4
- */
5
- export declare function exchangeTicket(ticket: string): Promise<ExchangeTicketResponse>;
6
- /**
7
- * Create a typed auth error
8
- */
9
- export declare function createAuthError(type: AuthError['type'], message: string, originalError?: unknown): AuthError;
10
- /**
11
- * Type guard for AuthError
12
- */
13
- export declare function isAuthError(error: unknown): error is AuthError;
14
- //# sourceMappingURL=ticketExchange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ticketExchange.d.ts","sourceRoot":"","sources":["../../src/utils/ticketExchange.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAElE;;GAEG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAkDpF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EACvB,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,OAAO,GACtB,SAAS,CAMX;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAO9D"}
@@ -1,54 +0,0 @@
1
- import { AUTH_CONFIG, AUTH_ENDPOINTS } from '../constants';
2
- /**
3
- * Exchange a one-time ticket for Supabase session tokens
4
- */
5
- export async function exchangeTicket(ticket) {
6
- const url = `${AUTH_CONFIG.AUTH_BROKER_URL}${AUTH_ENDPOINTS.EXCHANGE_TICKET}`;
7
- try {
8
- const response = await fetch(url, {
9
- method: 'POST',
10
- headers: {
11
- 'Content-Type': 'application/json',
12
- },
13
- body: JSON.stringify({ ticket }),
14
- });
15
- if (!response.ok) {
16
- const errorData = await response.json().catch(() => ({}));
17
- if (response.status === 401) {
18
- throw createAuthError('INVALID_TICKET', errorData.detail || 'Invalid or expired ticket');
19
- }
20
- throw createAuthError('EXCHANGE_FAILED', errorData.detail || `Ticket exchange failed: ${response.status}`);
21
- }
22
- const data = await response.json();
23
- return data;
24
- }
25
- catch (error) {
26
- if (isAuthError(error)) {
27
- throw error;
28
- }
29
- // Network or other errors
30
- if (error instanceof TypeError && error.message.includes('fetch')) {
31
- throw createAuthError('NETWORK_ERROR', 'Network error during ticket exchange. Please check your connection.', error);
32
- }
33
- throw createAuthError('EXCHANGE_FAILED', error instanceof Error ? error.message : 'Unknown error during ticket exchange', error);
34
- }
35
- }
36
- /**
37
- * Create a typed auth error
38
- */
39
- export function createAuthError(type, message, originalError) {
40
- return {
41
- type,
42
- message,
43
- originalError,
44
- };
45
- }
46
- /**
47
- * Type guard for AuthError
48
- */
49
- export function isAuthError(error) {
50
- return (typeof error === 'object' &&
51
- error !== null &&
52
- 'type' in error &&
53
- 'message' in error);
54
- }