Mobile support to come.
import "server-only";
import {
type CreateUserRequest,
type UserRepositoriesResponse,
UserRepositoriesResponseSchema,
type UserResponse,
UserResponseSchema,
} from "../dto";
import { getSession } from "../supabase";
import {
authFetch,
authHead,
authPost,
GITDOT_SERVER_URL,
handleResponse,
NotFound,
} from "./util";
export async function hasUser(username: string): Promise<boolean> {
const response = await authHead(`${GITDOT_SERVER_URL}/user/${username}`);
return response.ok;
}
export async function getUser(username: string): Promise<UserResponse | null> {
const response = await authFetch(`${GITDOT_SERVER_URL}/user/${username}`);
return await handleResponse(response, UserResponseSchema);
}
export async function createUser(username: string): Promise<UserResponse | null> {
const response = await authPost(`${GITDOT_SERVER_URL}/user`, { name: username });
return await handleResponse(response, UserResponseSchema);
}
export async function listUserRepositories(
username: string,
): Promise<UserRepositoriesResponse | NotFound | null> {
const response = await authFetch(
`${GITDOT_SERVER_URL}/user/${username}/repositories`,
);
if (response.status === 404) return NotFound;
return await handleResponse(response, UserRepositoriesResponseSchema);
}
/**
* this should _not_ be used on any page that we intend to statically render
* if static pages require auth, rely on useUser in client-side components instead
*/
export async function getCurrentUser(): Promise<UserResponse | null> {
const session = await getSession();
if (!session) return null;
const response = await authFetch(`${GITDOT_SERVER_URL}/user`);
return await handleResponse(response, UserResponseSchema);
}
wip - wire up our user dto creation
baepaul•1714b5b1d ago
refactoring validate user -> hasUser and wiring up signup form
baepaul•3fea7211d ago
for the subways
baepaul•96d95bd2d ago
refactoring to head -> /user/{username} for username existence checks
baepaul•2aaa7a42d ago
replaced create_user api with validate_name api
mikkel•0e0bf523d ago
created temporary signup page
mikkel•5a9138b3d ago
styling login form + re organizing auth paths
baepaul•b49ac0c8d ago
new 404 error in authorization service and NotFoudn
baepaul•432dc8e9d ago
nits, fixing answer form flicker and stuff
baepaul•7969fad9d ago
re-designing user page to have user repos and create repo button
baepaul•bc9653810d ago
making unauth views work, but introduces flicker for answer form on questions...
baepaul•38d9d4b10d ago
renaming env variable
baepaul•65fcc7a11d ago
adding user provider and organizing different views
baepaul•a92fc2412d ago
wiring up user-provider paradigm (fetch current user metadata + stream it back down)
baepaul•da2de8c12d ago