Skip to content

Commit

Permalink
feat: init server auth plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Dec 2, 2024
1 parent ab0e23e commit 086591c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/server/client/query/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { apiClient } from "@client/lib/api-fetch"
import { getHydrateData } from "@client/lib/helper"
import { getProviders } from "@follow/shared/auth"
import { capitalizeFirstLetter, isBizId, parseUrl } from "@follow/utils/utils"
import { useQuery } from "@tanstack/react-query"

Expand Down Expand Up @@ -59,7 +60,7 @@ export const useUserQuery = (handleOrId: string | undefined) => {
export const useAuthProviders = () => {
return useQuery({
queryKey: ["providers"],
queryFn: () => apiClient["auth-app"].providers.$get(),
queryFn: async () => (await getProviders()).data,
placeholderData: {
google: {
id: "google",
Expand Down
12 changes: 11 additions & 1 deletion packages/shared/src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { env } from "@follow/shared/env"
import type { authPlugins } from "@follow/shared/hono"
import type { BetterAuthClientPlugin } from "better-auth/client"
import { createAuthClient } from "better-auth/react"

import { IN_ELECTRON, WEB_URL } from "./constants"

const serverPlugins = [
{
id: "getProviders",
$InferServerPlugin: {} as (typeof authPlugins)[0],
},
] satisfies BetterAuthClientPlugin[]

const authClient = createAuthClient({
baseURL: `${env.VITE_API_URL}/better-auth`,
plugins: serverPlugins,
})

export const { signIn, signOut, getSession } = authClient
export const { signIn, signOut, getSession, getProviders } = authClient

export const LOGIN_CALLBACK_URL = `${WEB_URL}/login`
export type LoginRuntime = "browser" | "app"
Expand Down
72 changes: 68 additions & 4 deletions packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as hono_hono_base from 'hono/hono-base';
import * as hono_types from 'hono/types';
import * as hono_utils_http_status from 'hono/utils/http-status';
import { HttpBindings } from '@hono/node-server';
import * as better_call from 'better-call';
import * as zod from 'zod';
import { z } from 'zod';
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
Expand All @@ -10,12 +11,35 @@ import * as drizzle_orm from 'drizzle-orm';
import { InferInsertModel, SQL } from 'drizzle-orm';
import * as better_auth_adapters_drizzle from 'better-auth/adapters/drizzle';
import * as better_auth from 'better-auth';
import * as better_call from 'better-call';

type Env = {
Bindings: HttpBindings;
};

declare const authPlugins: {
id: "getProviders";
endpoints: {
getProviders: {
<C extends [(better_call.Context<"/get-providers", {
method: "GET";
}> | undefined)?]>(...ctx: C): Promise<C extends [{
asResponse: true;
}] ? Response : {
[k: string]: {
id: string;
name: string;
};
}>;
path: "/get-providers";
options: {
method: "GET";
};
method: better_call.Method | better_call.Method[];
headers: Headers;
};
};
}[];

declare const achievements: drizzle_orm_pg_core.PgTableWithColumns<{
name: "achievements";
schema: undefined;
Expand Down Expand Up @@ -6547,6 +6571,24 @@ declare const auth: {
path: "/get-session";
};
} & {
getProviders: {
<C extends [(better_call.Context<"/get-providers", {
method: "GET";
}> | undefined)?]>(...ctx: C): Promise<C extends [{
asResponse: true;
}] ? Response : {
[k: string]: {
id: string;
name: string;
};
}>;
path: "/get-providers";
options: {
method: "GET";
};
method: better_call.Method | better_call.Method[];
headers: Headers;
};
signInSocial: {
<C extends [better_call.Context<"/sign-in/social", {
method: "POST";
Expand Down Expand Up @@ -9065,7 +9107,29 @@ declare const auth: {
clientSecret: string;
} | undefined;
};
plugins: {
plugins: ({
id: "getProviders";
endpoints: {
getProviders: {
<C extends [(better_call.Context<"/get-providers", {
method: "GET";
}> | undefined)?]>(...ctx: C): Promise<C extends [{
asResponse: true;
}] ? Response : {
[k: string]: {
id: string;
name: string;
};
}>;
path: "/get-providers";
options: {
method: "GET";
};
method: better_call.Method | better_call.Method[];
headers: Headers;
};
};
} | {
id: "custom-session";
endpoints: {
getSession: {
Expand Down Expand Up @@ -9115,7 +9179,7 @@ declare const auth: {
headers: Headers;
};
};
}[];
})[];
};
$context: Promise<better_auth.AuthContext>;
$Infer: {
Expand Down Expand Up @@ -11945,4 +12009,4 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
}, "/probes">, "/">;
type AppType = typeof _routes;

export { type ActionsModel, type AirdropActivity, type AppType, type AttachmentsModel, type AuthSession, CommonEntryFields, type ConditionItem, type DetailModel, type EntriesModel, type EntryReadHistoriesModel, type ExtraModel, type FeedModel, type MediaModel, type MessagingData, MessagingType, type SettingsModel, account, accountAuthjs, achievements, achievementsOpenAPISchema, actions, actionsItemOpenAPISchema, actionsOpenAPISchema, actionsRelations, activityEnum, airdrops, airdropsOpenAPISchema, attachmentsZodSchema, boosts, collections, collectionsOpenAPISchema, collectionsRelations, detailModelSchema, entries, entriesOpenAPISchema, entriesRelations, entryReadHistories, entryReadHistoriesOpenAPISchema, entryReadHistoriesRelations, extraZodSchema, feedPowerTokens, feedPowerTokensOpenAPISchema, feedPowerTokensRelations, feeds, feedsOpenAPISchema, feedsRelations, inboxHandleSchema, inboxes, inboxesEntries, inboxesEntriesInsertOpenAPISchema, type inboxesEntriesModel, inboxesEntriesOpenAPISchema, inboxesEntriesRelations, inboxesOpenAPISchema, inboxesRelations, invitations, invitationsOpenAPISchema, invitationsRelations, languageSchema, levels, levelsOpenAPISchema, levelsRelations, lists, listsOpenAPISchema, listsRelations, listsSubscriptions, listsSubscriptionsOpenAPISchema, listsSubscriptionsRelations, listsTimeline, listsTimelineOpenAPISchema, listsTimelineRelations, lower, mediaZodSchema, messaging, messagingOpenAPISchema, messagingRelations, session, sessionAuthjs, settings, subscriptions, subscriptionsOpenAPISchema, subscriptionsRelations, timeline, timelineOpenAPISchema, timelineRelations, transactionType, transactions, transactionsOpenAPISchema, transactionsRelations, user, users, usersOpenApiSchema, usersRelations, verification, wallets, walletsOpenAPISchema, walletsRelations };
export { type ActionsModel, type AirdropActivity, type AppType, type AttachmentsModel, type AuthSession, CommonEntryFields, type ConditionItem, type DetailModel, type EntriesModel, type EntryReadHistoriesModel, type ExtraModel, type FeedModel, type MediaModel, type MessagingData, MessagingType, type SettingsModel, account, accountAuthjs, achievements, achievementsOpenAPISchema, actions, actionsItemOpenAPISchema, actionsOpenAPISchema, actionsRelations, activityEnum, airdrops, airdropsOpenAPISchema, attachmentsZodSchema, authPlugins, boosts, collections, collectionsOpenAPISchema, collectionsRelations, detailModelSchema, entries, entriesOpenAPISchema, entriesRelations, entryReadHistories, entryReadHistoriesOpenAPISchema, entryReadHistoriesRelations, extraZodSchema, feedPowerTokens, feedPowerTokensOpenAPISchema, feedPowerTokensRelations, feeds, feedsOpenAPISchema, feedsRelations, inboxHandleSchema, inboxes, inboxesEntries, inboxesEntriesInsertOpenAPISchema, type inboxesEntriesModel, inboxesEntriesOpenAPISchema, inboxesEntriesRelations, inboxesOpenAPISchema, inboxesRelations, invitations, invitationsOpenAPISchema, invitationsRelations, languageSchema, levels, levelsOpenAPISchema, levelsRelations, lists, listsOpenAPISchema, listsRelations, listsSubscriptions, listsSubscriptionsOpenAPISchema, listsSubscriptionsRelations, listsTimeline, listsTimelineOpenAPISchema, listsTimelineRelations, lower, mediaZodSchema, messaging, messagingOpenAPISchema, messagingRelations, session, sessionAuthjs, settings, subscriptions, subscriptionsOpenAPISchema, subscriptionsRelations, timeline, timelineOpenAPISchema, timelineRelations, transactionType, transactions, transactionsOpenAPISchema, transactionsRelations, user, users, usersOpenApiSchema, usersRelations, verification, wallets, walletsOpenAPISchema, walletsRelations };

0 comments on commit 086591c

Please sign in to comment.