a tool for shared writing and social publishing
1"use client";
2
3import { OAuthSessionError } from "src/atproto-oauth";
4
5export function OAuthErrorMessage({
6 error,
7 className,
8}: {
9 error: OAuthSessionError;
10 className?: string;
11}) {
12 const signInUrl = `/api/oauth/login?redirect_url=${encodeURIComponent(window.location.href)}${error.did ? `&handle=${encodeURIComponent(error.did)}` : ""}`;
13
14 return (
15 <div className={className}>
16 <span>Your session has expired or is invalid. </span>
17 <a href={signInUrl} className="underline font-bold whitespace-nowrap">
18 Sign in again
19 </a>
20 </div>
21 );
22}
23
24export function isOAuthSessionError(
25 error: unknown,
26): error is OAuthSessionError {
27 return (
28 typeof error === "object" &&
29 error !== null &&
30 "type" in error &&
31 (error as OAuthSessionError).type === "oauth_session_expired"
32 );
33}