mirror of
https://github.com/oxynote/oxynote.git
synced 2026-10-18 11:29:20 +02:00
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
export interface AuthError {
|
|
message?: string | undefined
|
|
status: number
|
|
statusText: string
|
|
code?: string | undefined
|
|
}
|
|
|
|
export interface AuthResponse {
|
|
error?: AuthError | null
|
|
}
|
|
|
|
export function postAuthDocumentUrl(
|
|
baseUrl: string | undefined,
|
|
next: string | undefined,
|
|
defaultPath = "/",
|
|
): string {
|
|
return `${baseUrl || ""}${next ? decodeURIComponent(next) : defaultPath}`
|
|
}
|
|
|
|
// a server redirect to the login page cannot put the hash in next, because
|
|
// the server never sees one. The browser keeps it on the login url instead,
|
|
// so it is added back here
|
|
export function nextUrlWithHash(
|
|
next: string | undefined,
|
|
hash: string,
|
|
): string | undefined {
|
|
return next ? next + encodeURIComponent(hash) : undefined
|
|
}
|
|
|
|
// the accept page renders from these parameters before the invitee has a
|
|
// session. auth-realtime builds the same link for the invitation email
|
|
// (invitationLink in server/auth-realtime/src/auth.ts).
|
|
export function acceptInvitationUrl(
|
|
baseUrl: string | undefined,
|
|
invitation: {
|
|
id: string
|
|
email: string
|
|
inviter: string
|
|
organizationName: string
|
|
organizationId: string
|
|
},
|
|
): string {
|
|
const query = new URLSearchParams({
|
|
id: invitation.id,
|
|
email: invitation.email,
|
|
inviter: invitation.inviter,
|
|
orgName: invitation.organizationName,
|
|
orgId: invitation.organizationId,
|
|
})
|
|
|
|
return `${baseUrl || ""}/accept-invite?${query.toString()}`
|
|
}
|
|
|
|
// whether a login or signup page was opened on the way to accepting an
|
|
// invitation. The next path arrives URI-encoded, and a malformed one is no
|
|
// invitation.
|
|
export function isInvitationRedirect(next: unknown): boolean {
|
|
if (typeof next !== "string") {
|
|
return false
|
|
}
|
|
|
|
try {
|
|
return decodeURIComponent(next).startsWith("/accept-invite")
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export function postEmailVerificationUrl(
|
|
baseUrl: string | undefined,
|
|
email: string,
|
|
): string {
|
|
return `${baseUrl || ""}/verify-email?new=${encodeURIComponent(email)}`
|
|
}
|