Skip to content

Commit

Permalink
⚡ Make email in signInAnon optional
Browse files Browse the repository at this point in the history
  • Loading branch information
lowczarc committed Nov 1, 2023
1 parent 5043ab8 commit a6b06c2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ApiError, ErrorData } from "./helpers/error";
type SimpleProvider = "github" | "google";
type LoginWithFirebaseInput = { token: string; provider: "firebase" };
type LoginWithCustomInput = { token: string; provider: "custom" };
type LoginAnonymousInput = { provider: "anonymous"; email: string };
type LoginAnonymousInput = { provider: "anonymous"; email?: string };
type LoginFunctionInput =
| SimpleProvider
| { provider: SimpleProvider }
Expand Down Expand Up @@ -126,14 +126,17 @@ export async function signInWithOAuthToken(
}

export async function signInAnon(
email: string,
email: string | undefined,
co: MutablePromise<Partial<ClientOptions>>,
{ project, endpoint }: { project: string; endpoint: string },
): Promise<void> {
const emailBase64 = Buffer.from(email).toString("base64");
let basic = "auto";
if (email) {
basic = Buffer.from(email).toString("base64");
}
try {
const { data } = await axios.get(`${endpoint}/project/${project}/auth/anonymous`, {
headers: { Authorization: `Bearer ${emailBase64}` },
headers: { Authorization: `Basic ${basic}` },
});

co.set({ token: data, endpoint });
Expand Down

0 comments on commit a6b06c2

Please sign in to comment.