@xouteiro/auth_npm 1.0.0 → 1.0.1
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/index.js +2307 -0
- package/dist/index.mjs +2290 -0
- package/package.json +14 -6
- package/src/AuthWrapper.jsx +13 -9
- package/src/LogoutButton.jsx +12 -0
- package/src/index.js +5 -0
- package/src/supabaseClient.js +9 -3
- package/src/useAuth.js +24 -0
- package/src/utils.js +4 -0
- package/tsup.config.js +13 -0
package/package.json
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xouteiro/auth_npm",
|
3
|
-
"version": "1.0.
|
4
|
-
"description": "",
|
5
|
-
"main": "index.js",
|
3
|
+
"version": "1.0.1",
|
4
|
+
"description": "Authentication package for Supabase",
|
5
|
+
"main": "src/index.js",
|
6
6
|
"scripts": {
|
7
|
-
"
|
7
|
+
"build": "tsup"
|
8
8
|
},
|
9
|
-
"keywords": [
|
9
|
+
"keywords": [
|
10
|
+
"supabase",
|
11
|
+
"auth",
|
12
|
+
"authentication"
|
13
|
+
],
|
10
14
|
"author": "",
|
11
15
|
"license": "ISC",
|
12
16
|
"dependencies": {
|
@@ -15,6 +19,10 @@
|
|
15
19
|
"@supabase/supabase-js": "^2.52.1"
|
16
20
|
},
|
17
21
|
"devDependencies": {
|
18
|
-
"
|
22
|
+
"@types/react": "^19.1.9",
|
23
|
+
"@types/react-dom": "^19.1.7",
|
24
|
+
"esbuild": "^0.25.8",
|
25
|
+
"tsup": "^8.5.0",
|
26
|
+
"typescript": "^5.9.2"
|
19
27
|
}
|
20
28
|
}
|
package/src/AuthWrapper.jsx
CHANGED
@@ -1,35 +1,39 @@
|
|
1
|
-
import {
|
1
|
+
import { useState, useEffect } from 'react'
|
2
2
|
import { Auth } from '@supabase/auth-ui-react'
|
3
3
|
import { ThemeSupa } from '@supabase/auth-ui-shared'
|
4
4
|
import { supabase } from './supabaseClient'
|
5
5
|
|
6
|
-
export default function AuthWrapper({ onAuth }) {
|
6
|
+
export default function AuthWrapper({ onAuth, providers = ['google', 'github'], theme = 'dark' }) {
|
7
|
+
if (!supabase) {
|
8
|
+
throw new Error('Supabase client is not initialized. Call initializeSupabase() before using AuthWrapper.')
|
9
|
+
}
|
10
|
+
|
7
11
|
const [session, setSession] = useState(null)
|
8
12
|
|
9
13
|
useEffect(() => {
|
10
14
|
supabase.auth.getSession().then(({ data: { session } }) => {
|
11
15
|
setSession(session)
|
12
|
-
if (session) onAuth(session)
|
16
|
+
if (session) onAuth?.(session)
|
13
17
|
})
|
14
18
|
|
15
19
|
const { data: subscription } = supabase.auth.onAuthStateChange((_event, session) => {
|
16
20
|
setSession(session)
|
17
|
-
if (session) onAuth(session)
|
21
|
+
if (session) onAuth?.(session)
|
18
22
|
})
|
19
23
|
|
20
|
-
return () => subscription
|
21
|
-
}, [])
|
24
|
+
return () => subscription?.unsubscribe()
|
25
|
+
}, [onAuth])
|
22
26
|
|
23
27
|
if (!session) {
|
24
28
|
return (
|
25
29
|
<Auth
|
26
30
|
supabaseClient={supabase}
|
27
31
|
appearance={{ theme: ThemeSupa }}
|
28
|
-
providers={
|
29
|
-
theme=
|
32
|
+
providers={providers}
|
33
|
+
theme={theme}
|
30
34
|
/>
|
31
35
|
)
|
32
36
|
}
|
33
37
|
|
34
38
|
return <div>✅ Logged in as: {session.user.email}</div>
|
35
|
-
}
|
39
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { useAuth } from './useAuth'
|
2
|
+
|
3
|
+
export default function LogoutButton({ supabaseClient, onLogout }) {
|
4
|
+
const { signOut } = useAuth(supabaseClient)
|
5
|
+
|
6
|
+
const handleLogout = async () => {
|
7
|
+
await signOut()
|
8
|
+
onLogout?.()
|
9
|
+
}
|
10
|
+
|
11
|
+
return <button onClick={handleLogout}>🚪 Log out</button>
|
12
|
+
}
|
package/src/index.js
ADDED
package/src/supabaseClient.js
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
import { createClient } from '@supabase/supabase-js'
|
2
2
|
|
3
|
-
|
4
|
-
const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY
|
3
|
+
let supabase = null
|
5
4
|
|
6
|
-
export
|
5
|
+
export function initializeSupabase(url, anonKey) {
|
6
|
+
if (!url || !anonKey) {
|
7
|
+
throw new Error('Supabase URL and Anon Key are required to initialize the client.')
|
8
|
+
}
|
9
|
+
supabase = createClient(url, anonKey)
|
10
|
+
}
|
11
|
+
|
12
|
+
export { supabase }
|
package/src/useAuth.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { useState, useEffect } from 'react'
|
2
|
+
|
3
|
+
export function useAuth(supabaseClient) {
|
4
|
+
const [session, setSession] = useState(null)
|
5
|
+
|
6
|
+
useEffect(() => {
|
7
|
+
supabaseClient.auth.getSession().then(({ data: { session } }) => {
|
8
|
+
setSession(session)
|
9
|
+
})
|
10
|
+
|
11
|
+
const { data: subscription } = supabaseClient.auth.onAuthStateChange((_event, session) => {
|
12
|
+
setSession(session)
|
13
|
+
})
|
14
|
+
|
15
|
+
return () => subscription?.unsubscribe()
|
16
|
+
}, [supabaseClient])
|
17
|
+
|
18
|
+
const signOut = async () => {
|
19
|
+
await supabaseClient.auth.signOut()
|
20
|
+
setSession(null)
|
21
|
+
}
|
22
|
+
|
23
|
+
return { session, signOut }
|
24
|
+
}
|
package/src/utils.js
ADDED
package/tsup.config.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { defineConfig } from 'tsup'
|
2
|
+
|
3
|
+
export default defineConfig({
|
4
|
+
entry: ['src/index.js'], // Entry point for your package
|
5
|
+
format: ['esm', 'cjs'], // Output formats
|
6
|
+
clean: true, // Clean the output directory before building
|
7
|
+
esbuildOptions(options) {
|
8
|
+
options.loader = {
|
9
|
+
'.js': 'jsx', // Treat .js files as JSX
|
10
|
+
'.jsx': 'jsx', // Treat .jsx files as JSX
|
11
|
+
}
|
12
|
+
},
|
13
|
+
})
|