Skip to content
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

update auth to better-auth v1 #71

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

wtfdivyansh
Copy link
Contributor

@wtfdivyansh wtfdivyansh commented Nov 26, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced the Account Switcher with a new "Logout" button for logging out of all sessions and an "Add Account" link for easy account management.
    • Improved session management by transitioning from session IDs to session tokens.
  • Bug Fixes

    • Updated session handling to ensure accurate session token usage.
  • Dependencies

    • Upgraded the better-auth package to a stable version (1.0.5) across multiple components.
  • Database Changes

    • Significant schema updates to improve account and session management, including new fields and unique constraints.

Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plura-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 4:09pm
plura-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 4:09pm
plura-status ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 4:09pm
plura-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 4:09pm

Copy link

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces significant changes to the AccountSwitcher component, focusing on session management by transitioning from session IDs to session tokens. A new asynchronous function for signing out has been added, along with updated UI elements for logging out and adding accounts. Additionally, the package.json files for both the plura-www and @repo/auth packages reflect an upgrade to the stable version of the better-auth dependency. Database schema changes include new fields and constraints across multiple tables, enhancing the handling of sessions and accounts.

Changes

File Path Change Summary
apps/www/components/custom/account-switcher.tsx - Updated onSelect method to accept token instead of sessionId.
- Added handleCurrentSignOut method for session revocation and page reload.
- Updated <select> and <option> elements to use session.token.
- Changed button text from "logout" to "Logout" and added "Add Account" link.
apps/www/package.json - Updated better-auth dependency from 0.8.1-beta.1 to 1.0.5.
packages/auth/package.json - Updated better-auth dependency from 0.8.6-beta.4 to 1.0.5.
- Modified entry for @repo/typescript-config (removed and re-added).
packages/auth/tsconfig.json - Added trailing comma in JSON formatting.
packages/database/prisma/migrations/.../migration.sql - Dropped expiresAt column, added new columns in account and session tables, created unique index on token.
packages/database/prisma/schema.prisma - Updated Session, Account, and Verification models with new fields and constraints.
packages/typescript-config/base.json - Added trailing comma in JSON formatting.

Possibly related PRs

  • feat/(usage_page) #21: Changes in the AccountSwitcher may relate to new layout management and user navigation improvements in the UsagePage and AppLayout.
  • Feature/auth page #24: Modifications in session handling could be relevant to the overall authentication flow addressed in the auth page changes.
  • feature/auth #33: Updates to API route handling and session management may connect with changes in the AccountSwitcher.
  • auth #34: Modifications in API routes for authentication could relate to session management changes in the AccountSwitcher.
  • fix socal signin #56: Fix for the social sign-in URL may be relevant to session management and user authentication changes in the AccountSwitcher.
  • fix imports #58: Import fixes may not directly relate but could be part of a broader effort including session management updates.

🐰 In the meadow where rabbits play,
A switcher now leads the way!
Tokens in hand, we hop along,
Logout and add accounts, oh so strong!
With every change, our joy will grow,
In the world of code, we’ll steal the show! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Nov 26, 2024

@wtfdivyansh is attempting to deploy a commit to the BlueFinZ Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (6)
packages/database/prisma/schema.prisma (2)

30-32: Consider consolidating session identifiers

The model now has both an id primary key and a unique token field. Since we're transitioning to token-based sessions, consider using the token as the primary identifier to avoid confusion and maintain a single source of truth.

 model Session {
-  id        String   @id
   token     String   @id
   expiresAt DateTime
   createdAt DateTime
   updatedAt DateTime
   ipAddress String?
   userAgent String?
   userId    String
   user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)

-  @@unique([token])
   @@map("session")
 }

Also applies to: 38-38


43-56: Add security and performance optimizations

  1. Security Considerations:

    • The password field should be properly hashed before storage
    • Access tokens and refresh tokens should be encrypted at rest
  2. Performance Optimization:

    • Consider adding indexes for userId and accountId which are likely to be frequently queried
 model Account {
   // ... existing fields ...
+  @@index([userId])
+  @@index([accountId])
 }
packages/database/prisma/migrations/20241126154111_final_auth/migration.sql (1)

22-24: Review token storage security implications

The session token is stored as plain text. Consider whether this meets security requirements:

  1. Ensure the token is cryptographically secure
  2. Consider whether additional encryption at rest is needed
  3. Verify token rotation/invalidation mechanisms are in place
apps/www/components/custom/account-switcher.tsx (3)

12-15: Remove debugging console.log statements

Production code should not contain console.log statements.

-  console.log(token);

Line range hint 12-19: Consider improving the user experience after session switch

Instead of reloading the entire page, consider using a more seamless approach:

  1. Update the client-side state
  2. Show a loading state during the transition
  3. Refresh only the necessary data
   const onSelect = async (token: string) => {
-    console.log(token);
     const active = await authClient.multiSession.setActive({
       sessionToken: token,
     });
-    console.log(active);
-    window.location.reload();
+    // Show loading state
+    setIsLoading(true);
+    // Refresh necessary data
+    await refreshUserData();
+    // Update UI
+    setIsLoading(false);
   };

Line range hint 47-74: Improve accessibility and UI consistency

Several accessibility and UI consistency issues need attention:

  1. Use semantic HTML buttons instead of divs for clickable elements
  2. Add proper ARIA attributes
  3. Consistent text casing for actions
   <select
     onChange={(e) => onSelect(e.target.value)}
     value={activeSession.session.token}
-    className="border-2 border-gray-300[0.3] rounded-md p-2"
+    className="border-2 border-gray-300[0.3] rounded-md p-2"
+    aria-label="Switch active account"
   >
-  <div
-    className="flex border border-neutral-900[0.2] bg-neutral-900/60 p-2"
+  <button
+    className="flex border border-neutral-900[0.2] bg-neutral-900/60 p-2"
     onClick={handleSignOut}
+    aria-label="Sign out from all accounts"
   >
-    Logout from all
-  </div>
+    Log Out From All
+  </button>
-  <div
-    className="flex border border-neutral-900[0.2] bg-neutral-900/60 p-2"
+  <button
+    className="flex border border-neutral-900[0.2] bg-neutral-900/60 p-2"
     onClick={handleCurrentSignOut}
+    aria-label="Sign out from current account"
   >
-    Logout
-  </div>
+    Log Out
+  </button>
   <Link href={"/auth"}>
-    <div className="flex border border-neutral-900[0.2] bg-neutral-900/60 p-2">
+    <button className="flex border border-neutral-900[0.2] bg-neutral-900/60 p-2">
       Add Account
-    </div>
+    </button>
   </Link>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cdd9ef8 and f9c6646.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • apps/www/components/custom/account-switcher.tsx (3 hunks)
  • apps/www/package.json (1 hunks)
  • packages/auth/package.json (1 hunks)
  • packages/auth/tsconfig.json (1 hunks)
  • packages/database/prisma/migrations/20241126154111_final_auth/migration.sql (1 hunks)
  • packages/database/prisma/schema.prisma (2 hunks)
  • packages/typescript-config/base.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/auth/tsconfig.json
  • packages/typescript-config/base.json
🔇 Additional comments (11)
packages/auth/package.json (3)

15-16: Verify compatibility between better-auth and better-call

There might be compatibility issues between the stable better-auth v1.0.5 and the beta version of better-call (0.2.14-beta.3).

✅ Verification successful

No compatibility issues found between better-auth and better-call

Based on the analysis of the dependencies:

  • better-auth v1.0.5 includes better-call v0.3.3-beta.2 as a dependency
  • The package.json specifies better-call v0.2.14-beta.3 directly
  • Both versions of better-call have identical dependencies (@better-fetch/fetch, rou3, set-cookie-parser, uncrypto)
  • The codebase shows no direct imports from better-call, suggesting it's an internal dependency of better-auth

Since better-call is primarily used internally by better-auth and there are no direct usages in the codebase, the version mismatch won't cause compatibility issues. The stable version of better-auth (1.0.5) has been tested with its bundled better-call version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for version compatibility issues

# Search for direct dependencies between packages
rg -A 5 "better-(auth|call)" 

# Look for potential integration points
ast-grep --pattern 'import { $$$ } from "better-auth"'
ast-grep --pattern 'import { $$$ } from "better-call"'

Length of output: 5487


15-15: Verify breaking changes in better-auth v1.0.5

The upgrade from better-auth 0.8.6-beta.4 to 1.0.5 represents a major version change. This could introduce breaking changes that need careful migration.


15-15: Verify security implications of the auth update

As this is an authentication library update, we need to ensure there are no known vulnerabilities in the new version.

Consider implementing a thorough testing plan for the authentication flow changes, especially around session token handling.

packages/database/prisma/schema.prisma (2)

21-21: LGTM: Accounts relation properly restored

The reintroduction of the accounts relation is correct and necessary for maintaining the relationship with the Account model.


Line range hint 1-85: Verify schema migration impact

Please ensure that:

  1. Migration scripts handle existing data appropriately
  2. Token-based session changes are backward compatible
  3. Account model changes don't affect existing authentication flows
✅ Verification successful

Schema changes are properly handled with migrations

The migration files show a clear progression of schema changes with appropriate handling:

  1. Initial auth setup (20241110144439_auth) creates the base tables with proper relations
  2. Social update (20241117140010_social) adds verification timestamps and Trigger model
  3. Final auth changes (20241126154111_final_auth) properly handles:
    • Session token uniqueness with session_token_key index
    • Account model refinements with separate expiry fields
    • All timestamp columns (createdAt/updatedAt) with proper migrations

The migrations include necessary warnings about required fields and handle potential data issues through proper ALTER TABLE statements. The schema is consistent with all migrations, and the changes maintain backward compatibility through careful column additions rather than destructive changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for related migration files and their content
fd -e sql -e prisma . | while read -r file; do
  echo "=== $file ==="
  cat "$file"
done

# Look for potential references to old session handling
rg -i "sessionId|session_id" --type ts --type js

Length of output: 6249

packages/database/prisma/migrations/20241126154111_final_auth/migration.sql (2)

27-28: Verify impact of making createdAt nullable in verification table

Making createdAt nullable in the verification table is unusual and could impact data integrity. This change might affect:

  1. Audit trails
  2. Verification expiration logic
  3. Data consistency checks
✅ Verification successful

Let me gather more information about the verification table and its usage.


Based on the gathered information, I can now provide the final response:

Making createdAt nullable in verification table is acceptable

The verification table is used for temporary verification records (like email verification codes) as indicated by the presence of expiresAt field. Making createdAt nullable while adding updatedAt suggests a design choice where the focus is on tracking when records are modified rather than created, which is reasonable for temporary verification data that gets cleaned up after expiration.

  • The schema shows Verification is a standalone entity without relations to other tables
  • No business logic was found that depends on createdAt for verification expiration (it uses dedicated expiresAt field)
  • The change doesn't impact data integrity as the verification records are temporary by nature
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for dependencies on createdAt in verification logic
rg -A 5 "verification.*createdAt"
ast-grep --pattern 'verification {
  $$$
  createdAt
  $$$
}'

Length of output: 699


Script:

#!/bin/bash
# Check schema definition and usage of verification table
fd schema.prisma --exec cat {}
rg -A 10 "verification" --type ts --type js

Length of output: 3056


30-31: Ensure proper index for session token lookups

The unique index on session tokens is good for preventing duplicates and optimizing lookups. However, verify:

  1. Token length constraints to prevent index size issues
  2. Impact on write performance
apps/www/package.json (2)

31-31: Verify breaking changes from better-auth beta to stable

This is a significant upgrade from a beta version (0.8.1-beta.1) to a stable version (1.0.5). Given the session management changes mentioned in the PR summary, ensure all breaking changes are properly handled.

✅ Verification successful

Let me gather more information about the auth implementation to better understand the impact.


Let me check the auth client implementation and the session handling code to understand if there are any breaking changes that need attention.


Based on the code analysis, I can now provide the final response:

Better-auth upgrade appears safe with current implementation

The codebase is already using the modern better-auth APIs and patterns that are compatible with v1.0.5:

  • Using the recommended multiSession plugin and its client counterpart
  • Proper session token handling in account switcher
  • Standard auth client setup with React hooks
  • Correct API implementation for session management

The implementation aligns well with better-auth's stable API patterns, and no breaking changes are evident in the current usage. The upgrade from beta to stable version should be safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for breaking changes and migration guides

# Search for migration guides or breaking changes in the codebase
rg -i "migration|upgrade|breaking.?changes" --type md

# Look for better-auth initialization or configuration files
fd -e ts -e js -e json "auth.?config|better.?auth.?(config)"

# Search for current usage patterns that might need updates
ast-grep --pattern 'import { $$$ } from "better-auth"'

Length of output: 264


Script:

#!/bin/bash
# Check the auth package implementation
cat packages/auth/src/auth.ts

# Look for better-auth usage patterns across the codebase
rg -l "better-auth" --type=ts --type=js

# Search for session-related code that might need updates
rg -l "session" --type=ts --type=js

# Look for any auth-related tests
fd -e test.ts -e test.js -e spec.ts -e spec.js auth

Length of output: 1783


Script:

#!/bin/bash
# Check the auth client implementation
cat apps/www/lib/auth-client.ts

# Check session-related implementations
cat apps/api/app/api/[[...route]]/session.ts
cat apps/www/components/custom/account-switcher.tsx

# Look for any migration guides in node_modules
cat node_modules/better-auth/CHANGELOG.md 2>/dev/null || echo "Changelog not found"
cat node_modules/better-auth/README.md 2>/dev/null || echo "README not found"

Length of output: 3341


31-31: Verify better-auth compatibility with React RC

The project uses React 19.0.0-rc. Verify that better-auth v1.0.5 is compatible with this React version, especially for session management features.

apps/www/components/custom/account-switcher.tsx (2)

4-4: LGTM!

The Link import is correctly added to support the new account addition feature.


12-15: Verify better-auth version compatibility

Ensure the token-based session management is compatible with the installed version of better-auth.

✅ Verification successful

Let me search for better-auth related files and dependencies to verify this further.


Let me check the auth client implementation and usage to verify the compatibility.


Token-based session management is correctly implemented and compatible

The implementation is using better-auth v1.0.5 with the proper multiSession plugin configuration. The token-based approach in account-switcher.tsx aligns with the better-auth setup in packages/auth/src/auth.ts and the client configuration using multiSessionClient().

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the installed version of better-auth
cat package.json | jq '.dependencies["better-auth"]'

# Look for any breaking changes in the migration guide
fd -t f "MIGRATION" -X cat {} 

Length of output: 91


Script:

#!/bin/bash
# Search for better-auth in all package.json files
fd package.json -x cat {} | grep -i "better-auth"

# Search for better-auth imports
rg "from ['\"]better-auth['\"]" -A 2

# Look for auth client initialization
ast-grep --pattern 'authClient = new $_'

Length of output: 463


Script:

#!/bin/bash
# Check auth client implementation
rg "multiSession.setActive" -A 3

# Check the auth client initialization and configuration
cat packages/auth/src/auth.ts

# Look for any version-specific implementations
ast-grep --pattern 'const authClient = $_'

Length of output: 1982

Comment on lines +66 to +67
createdAt DateTime?
updatedAt DateTime?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enforce timestamp consistency

Making createdAt and updatedAt optional deviates from standard practices and could lead to data consistency issues. Consider making these fields required with default values.

 model Verification {
   id         String    @id
   identifier String
   value      String
   expiresAt  DateTime
-  createdAt  DateTime?
-  updatedAt  DateTime?
+  createdAt  DateTime  @default(now())
+  updatedAt  DateTime  @updatedAt

   @@map("verification")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
createdAt DateTime?
updatedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

Comment on lines +4 to +10
- You are about to drop the column `expiresAt` on the `account` table. All the data in the column will be lost.
- A unique constraint covering the columns `[token]` on the table `session` will be added. If there are existing duplicate values, this will fail.
- Added the required column `createdAt` to the `account` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `account` table without a default value. This is not possible if the table is not empty.
- Added the required column `createdAt` to the `session` table without a default value. This is not possible if the table is not empty.
- Added the required column `token` to the `session` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `session` table without a default value. This is not possible if the table is not empty.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

⚠️ Migration might fail on non-empty tables

The migration adds multiple required columns (createdAt, updatedAt) without default values to both account and session tables. This will fail if these tables contain existing data.

Consider modifying the migration to handle existing data:

- ADD COLUMN     "createdAt" TIMESTAMP(3) NOT NULL,
- ADD COLUMN     "updatedAt" TIMESTAMP(3) NOT NULL
+ ADD COLUMN     "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ ADD COLUMN     "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +14 to +19
ALTER TABLE "account" DROP COLUMN "expiresAt",
ADD COLUMN "accessTokenExpiresAt" TIMESTAMP(3),
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL,
ADD COLUMN "refreshTokenExpiresAt" TIMESTAMP(3),
ADD COLUMN "scope" TEXT,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Data loss warning: expiresAt column dropped without migration

The migration script shows that the expiresAt column is being dropped with the warning "All the data in the column will be lost" and there's no data migration logic to transfer existing expiration data to the new accessTokenExpiresAt column. This is concerning because:

  • The account table was created in the previous migration (20241110144439_auth)
  • The current migration (20241126154111_final_auth) drops expiresAt without preserving its data
  • The new columns accessTokenExpiresAt and refreshTokenExpiresAt are nullable, but any existing expiration data will be lost

Suggested actions:

  • Add a data migration step to copy expiresAt values to accessTokenExpiresAt before dropping the column
  • Or confirm that data loss is acceptable if this is a development environment with no production data
🔗 Analysis chain

Verify data migration for removed expiresAt column

The expiresAt column is being dropped and replaced with more specific expiration columns. Ensure any existing expiration data is migrated appropriately.


Let me check the migration history to understand if this is a new table or if there's existing data that needs migration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there's existing data in the expiresAt column that needs migration
echo "Checking for existing expiration data..."
ast-grep --pattern 'expiresAt' # Look for usages in the codebase
rg -l "expiresAt" # Find files referencing this column

Length of output: 324


Script:

#!/bin/bash
# Check the previous migration that introduced the expiresAt column
cat packages/database/prisma/migrations/20241110144439_auth/migration.sql

# Check if there are any data migrations in the current migration
cat packages/database/prisma/migrations/20241126154111_final_auth/migration.sql

Length of output: 3275

Comment on lines +37 to +42
const handleCurrentSignOut = async () => {
await authClient.multiSession.revoke({
sessionToken: activeSession?.session.token
});
window.location.reload();
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and improve user experience

The current implementation lacks error handling and forces a page reload.

   const handleCurrentSignOut = async () => {
+    try {
+      setIsLoading(true);
       await authClient.multiSession.revoke({
         sessionToken: activeSession?.session.token
       });
-      window.location.reload();
+      router.push('/auth');
+    } catch (error) {
+      console.error('Failed to sign out:', error);
+      // Show error notification to user
+    } finally {
+      setIsLoading(false);
+    }
   };

Committable suggestion skipped: line range outside the PR's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants