-
Notifications
You must be signed in to change notification settings - Fork 882
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: authentication + pipe store stripe integration
- Loading branch information
1 parent
5e28618
commit 7d776b4
Showing
16 changed files
with
299 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ resolver = "2" | |
|
||
|
||
[workspace.package] | ||
version = "0.2.7" | ||
version = "0.2.8" | ||
authors = ["louis030195 <[email protected]>"] | ||
description = "" | ||
repository = "https://github.com/mediar-ai/screenpipe" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useState, useEffect, useCallback } from "react"; | ||
import { createStore } from "@tauri-apps/plugin-store"; | ||
import { localDataDir, join } from "@tauri-apps/api/path"; | ||
|
||
interface UserData { | ||
token: string; | ||
email: string; | ||
user_id: string; | ||
} | ||
|
||
interface UserState { | ||
isSignedIn: boolean; | ||
isLoading: boolean; | ||
error: string | null; | ||
user: UserData | null; | ||
checkLoomSubscription: () => Promise<boolean>; | ||
} | ||
|
||
let store: Awaited<ReturnType<typeof createStore>> | null = null; | ||
|
||
async function initStore() { | ||
const dataDir = await localDataDir(); | ||
const storePath = await join(dataDir, "screenpipe", "store.bin"); | ||
store = await createStore(storePath); | ||
const entries = await store.entries(); | ||
console.log("store", entries); | ||
} | ||
|
||
async function checkSubscription(email: string): Promise<boolean> { | ||
try { | ||
const isDev = window.location.href.includes("localhost"); | ||
const baseUrl = isDev ? "http://localhost:3001" : "https://screenpi.pe"; | ||
|
||
const response = await fetch(`${baseUrl}/api/stripe-loom`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
...(isDev ? {} : { credentials: "include" }), | ||
body: JSON.stringify({ email }), | ||
}); | ||
|
||
if (!response.ok) { | ||
console.error("subscription check failed with status:", response.status); | ||
return false; | ||
} | ||
|
||
const data = await response.json(); | ||
console.log("subscription data:", data); | ||
return data.hasActiveSubscription; | ||
} catch (error) { | ||
console.error("failed to check subscription:", error); | ||
return false; | ||
} | ||
} | ||
|
||
export function useUser() { | ||
const [user, setUser] = useState<UserData | null>(null); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const loadUser = async () => { | ||
if (!store) await initStore(); | ||
|
||
try { | ||
const savedUser = await store!.get<UserData>("auth_data"); | ||
setUser(savedUser || null); | ||
} catch (err) { | ||
console.error("failed to load user:", err); | ||
setError(err instanceof Error ? err.message : "failed to load user"); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
loadUser(); | ||
}, []); | ||
|
||
const checkLoomSubscription = useCallback(async () => { | ||
if (!user?.email) return false; | ||
return checkSubscription(user.email); | ||
}, [user?.email]); | ||
|
||
return { | ||
user, | ||
isSignedIn: !!user, | ||
isLoading, | ||
error, | ||
checkLoomSubscription, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.