-
Notifications
You must be signed in to change notification settings - Fork 1
chore(sidebar): handle session updates #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { authClient } from "$lib/auth"; | ||
import type { Session } from "better-auth"; | ||
import type { User } from "better-auth"; | ||
|
||
export class AuthStore { | ||
session = $state<Session>(); | ||
user = $state<User>(); | ||
|
||
async fetchSession() { | ||
const { data } = await authClient.getSession(); | ||
if (!data) return; | ||
this.session = data.session; | ||
this.user = data.user; | ||
} | ||
} | ||
|
||
export const authStore = new AuthStore(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<script lang="ts"> | ||
import packageJson from "../../../app/package.json"; | ||
import { onMount } from "svelte"; | ||
|
||
let version = $state(packageJson.version); | ||
const downloadUrlAarch64 = $derived( | ||
|
@@ -8,6 +9,17 @@ | |
const downloadUrlX64 = $derived( | ||
`https://github.com/getgrinta/grinta/releases/download/v${version}/Grinta_${version}_x64.dmg`, | ||
); | ||
|
||
onMount(() => { | ||
if (typeof window === "undefined") return; | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const fetchSession = searchParams.get("fetchSession"); | ||
if (fetchSession) { | ||
setTimeout(() => { | ||
window.grinta.fetchSession(); | ||
}, 1000); | ||
} | ||
}); | ||
Comment on lines
+13
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAdd type safety and error handling for robustness. The conditional session fetching based on URL parameters is a good approach for cross-component coordination. However, there are a few concerns that should be addressed: Apply this diff to improve type safety and error handling: onMount(() => {
if (typeof window === "undefined") return;
const searchParams = new URLSearchParams(window.location.search);
const fetchSession = searchParams.get("fetchSession");
if (fetchSession) {
setTimeout(() => {
- window.grinta.fetchSession();
+ if (window.grinta?.fetchSession) {
+ window.grinta.fetchSession().catch(console.error);
+ }
}, 1000);
}
}); The improvements include:
To verify the 🏁 Script executed: #!/bin/bash
# Description: Check for window.grinta type definitions
# Expected: Find type declarations for the grinta global object
rg -A 5 -B 5 "grinta.*fetchSession|window\.grinta" --type ts --type js Length of output: 1706 Ensure robust, type-safe invocation of The extension injects a • In onMount(() => {
if (typeof window === "undefined") return;
const searchParams = new URLSearchParams(window.location.search);
const fetchSession = searchParams.get("fetchSession");
if (fetchSession) {
setTimeout(() => {
- window.grinta.fetchSession();
+ // Only call if the extension has injected grinta.fetchSession
+ if (window.grinta?.fetchSession) {
+ window.grinta.fetchSession().catch(err => {
+ console.error("grinta.fetchSession failed:", err);
+ });
+ }
}, 1000);
}
}); • Declare the global declare interface Window {
grinta?: {
/** Injected by the browser extension */
fetchSession: () => Promise<void>;
};
} After adding that file, ensure your 🤖 Prompt for AI Agents
|
||
</script> | ||
|
||
<section | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling to prevent unhandled exceptions.
The
fetchSession
method lacks error handling. IfauthClient.getSession()
throws an exception, it will propagate unhandled, potentially crashing the application.Add proper error handling:
📝 Committable suggestion
🤖 Prompt for AI Agents