-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract better-auth and emitter packages
- Loading branch information
Showing
32 changed files
with
452 additions
and
522 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
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 |
---|---|---|
@@ -1,35 +1,3 @@ | ||
import { createAuthClient } from 'better-auth/client' | ||
import { createEmitter } from '~/helpers/emitter' | ||
import { createBetterAuthClient } from '@vxrn/better-auth' | ||
|
||
const keys = { | ||
token: 'TOKEN_KEY', | ||
session: 'SESSION_KEY', | ||
} | ||
|
||
const existingSession = | ||
typeof localStorage !== 'undefined' ? localStorage.getItem(keys.session) : '' | ||
|
||
export let authClient = existingSession | ||
? createAuthClientWithSession(existingSession) | ||
: createAuthClient() | ||
|
||
export const [emit, _, useRefreshAuthClient] = createEmitter<number>() | ||
|
||
globalThis['authClient'] = authClient | ||
|
||
function createAuthClientWithSession(session: string) { | ||
return createAuthClient({ | ||
fetchOptions: { | ||
headers: { | ||
Authorization: `Bearer ${session}`, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
export const setAuth = ({ token, session }: { token: string; session: string }) => { | ||
localStorage.setItem(keys.token, token) | ||
localStorage.setItem(keys.session, session) | ||
authClient = createAuthClientWithSession(session) | ||
emit(Math.random()) | ||
} | ||
export const { authClient, setAuthClientToken, useAuth } = createBetterAuthClient() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.