Skip to content

Commit fe1ded3

Browse files
committed
fix: Move route handler creator to server-actions
1 parent 6d0f2f8 commit fe1ded3

5 files changed

Lines changed: 19 additions & 20 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "dist/index.js",
77
"files": ["dist"],
88
"license": "WTFPL",
9-
"version": "1.1.0",
9+
"version": "1.1.1",
1010
"type": "module",
1111
"keywords": [
1212
"auth",

src/client.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { type ClientSession } from "./index";
4-
import { getSession } from "./server-actions";
54
import { createContext, useContext, type ReactNode } from "react";
65
import useSWR from "swr";
76

@@ -66,16 +65,3 @@ export function useUserInfo() {
6665

6766
return context;
6867
}
69-
70-
export const createSessionProviderRoute = () => {
71-
return async (_request: Request) => {
72-
const session = await getSession();
73-
74-
if (!session) {
75-
return Response.json({ error: "Not logged in" }, { status: 401 });
76-
} else {
77-
const { accessToken, refreshToken, ...clientSession } = session;
78-
return Response.json(clientSession);
79-
}
80-
};
81-
};

src/server-actions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { headers } from "next/headers";
22
import { cookies } from "next/headers";
33
import { redirect } from "next/navigation";
4-
import { type Session, getGlobalConfig } from "./index";
4+
import { type Session, type ClientSession, getGlobalConfig } from "./index";
55
import { RefreshAccessToken } from "./lib/oauth";
66
import jwt from "jsonwebtoken";
77

@@ -82,3 +82,16 @@ export const signOut = async (): Promise<Response> => {
8282
{ status: 200 },
8383
);
8484
};
85+
86+
export const createSessionProviderRoute = async (
87+
_request: Request,
88+
): Promise<Response> => {
89+
const session = await getSession();
90+
91+
if (!session) {
92+
return Response.json({ error: "Not logged in" }, { status: 401 });
93+
} else {
94+
const { accessToken, refreshToken, ...clientSession } = session;
95+
return Response.json(clientSession);
96+
}
97+
};

types/client.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ export declare function UserInfoProvider(props: {
1414
}): JSX.Element;
1515

1616
export declare function useUserInfo(): UserInfoContextType;
17-
18-
export declare function createSessionProviderRoute(
19-
request: Request,
20-
): Promise<Response>;

types/server-actions.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ export declare function getSession(): Promise<Session | null>;
55
export declare function signIn(): Promise<Response>;
66

77
export declare function signOut(): Promise<Response>;
8+
9+
export declare function createSessionProviderRoute(
10+
request: Request,
11+
): Promise<Response>;

0 commit comments

Comments
 (0)