getAccessToken
Utility function designed for retrieving authorization tokens within a component. It ensures that your React components have the necessary authentication state, either through OAuth or a personal access token.
Signature
function getAccessToken(): {
token: string;
type: "oauth" | "personal";
};
Return
The function returns an object containing the following properties:
token
: A string representing the access token.type
: An optional string that indicates the type of token retrieved. It can either beoauth
for OAuth tokens orpersonal
for personal access tokens.
Example
import { Detail } from "@raycast/api";
import { authorize } from "./oauth";
function AuthorizedComponent() {
const { token } = getAccessToken();
return <Detail markdown={`Access token: ${token}`} />;
}
export default withAccessToken({ authorize })(AuthorizedComponent);
Last updated