forked from aeharding/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
368 additions
and
280 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createSelector } from "@reduxjs/toolkit"; | ||
import { RootState } from "../../store"; | ||
import { parseJWT } from "../../helpers/lemmy"; | ||
import { getClient } from "../../services/lemmy"; | ||
|
||
export const activeAccount = createSelector( | ||
[ | ||
(state: RootState) => state.auth.accountData?.accounts, | ||
(state: RootState) => state.auth.accountData?.activeHandle, | ||
], | ||
(accounts, activeHandle) => { | ||
return accounts?.find(({ handle }) => handle === activeHandle); | ||
}, | ||
); | ||
|
||
export const jwtSelector = createSelector([activeAccount], (account) => { | ||
return account?.jwt; | ||
}); | ||
|
||
export const jwtPayloadSelector = createSelector([jwtSelector], (jwt) => | ||
jwt ? parseJWT(jwt) : undefined, | ||
); | ||
|
||
export const jwtIssSelector = (state: RootState) => | ||
jwtPayloadSelector(state)?.iss; | ||
|
||
export const handleSelector = createSelector([activeAccount], (account) => { | ||
return account?.handle; | ||
}); | ||
|
||
export const usernameSelector = createSelector([handleSelector], (handle) => { | ||
return handle?.split("@")[0]; | ||
}); | ||
|
||
export const urlSelector = (state: RootState) => | ||
jwtIssSelector(state) ?? state.auth.connectedInstance; | ||
|
||
export const clientSelector = createSelector( | ||
[urlSelector, jwtSelector], | ||
(url, jwt) => { | ||
// never leak the jwt to the incorrect server | ||
return getClient(url, jwt); | ||
}, | ||
); |
Oops, something went wrong.