@logto/next 3.2.7 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/index.cjs +24 -16
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +24 -16
- package/package.json +1 -1
package/lib/src/index.cjs
CHANGED
|
@@ -42,24 +42,32 @@ class LogtoClient extends client.default {
|
|
|
42
42
|
this.handleUser = (configs) => this.withLogtoApiRoute((request, response) => {
|
|
43
43
|
response.json(request.user);
|
|
44
44
|
}, configs);
|
|
45
|
-
this.handleAuthRoutes = (configs) => (request, response) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
this.handleAuthRoutes = (configs, onError) => (request, response) => {
|
|
46
|
+
try {
|
|
47
|
+
const { action } = request.query;
|
|
48
|
+
if (action === 'sign-in') {
|
|
49
|
+
return this.handleSignIn()(request, response);
|
|
50
|
+
}
|
|
51
|
+
if (action === 'sign-up') {
|
|
52
|
+
return this.handleSignIn(undefined, 'signUp')(request, response);
|
|
53
|
+
}
|
|
54
|
+
if (action === 'sign-in-callback') {
|
|
55
|
+
return this.handleSignInCallback()(request, response);
|
|
56
|
+
}
|
|
57
|
+
if (action === 'sign-out') {
|
|
58
|
+
return this.handleSignOut()(request, response);
|
|
59
|
+
}
|
|
60
|
+
if (action === 'user') {
|
|
61
|
+
return this.handleUser(configs)(request, response);
|
|
62
|
+
}
|
|
63
|
+
response.status(404).end();
|
|
58
64
|
}
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (onError) {
|
|
67
|
+
return onError(request, response, error);
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
61
70
|
}
|
|
62
|
-
response.status(404).end();
|
|
63
71
|
};
|
|
64
72
|
this.withLogtoApiRoute = (handler, config = {}, onError) => async (request, response) => {
|
|
65
73
|
try {
|
package/lib/src/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export default class LogtoClient extends LogtoNextBaseClient {
|
|
|
14
14
|
handleSignInCallback: (redirectTo?: string) => NextApiHandler;
|
|
15
15
|
handleSignOut: (redirectUri?: string) => NextApiHandler;
|
|
16
16
|
handleUser: (configs?: GetContextParameters) => NextApiHandler;
|
|
17
|
-
handleAuthRoutes: (configs?: GetContextParameters) => NextApiHandler;
|
|
17
|
+
handleAuthRoutes: (configs?: GetContextParameters, onError?: ((request: NextApiRequest, response: NextApiResponse, error: unknown) => unknown) | undefined) => NextApiHandler;
|
|
18
18
|
withLogtoApiRoute: (handler: NextApiHandler, config?: GetContextParameters, onError?: ((request: NextApiRequest, response: NextApiResponse, error: unknown) => unknown) | undefined) => NextApiHandler;
|
|
19
19
|
withLogtoSsr: <P extends Record<string, unknown> = Record<string, unknown>>(handler: (context: GetServerSidePropsContext) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>, configs?: GetContextParameters, onError?: ((error: unknown) => unknown) | undefined) => (context: GetServerSidePropsContext) => Promise<unknown>;
|
|
20
20
|
createNodeClientFromNextApi(request: IncomingMessage & {
|
package/lib/src/index.js
CHANGED
|
@@ -35,24 +35,32 @@ class LogtoClient extends LogtoNextBaseClient {
|
|
|
35
35
|
this.handleUser = (configs) => this.withLogtoApiRoute((request, response) => {
|
|
36
36
|
response.json(request.user);
|
|
37
37
|
}, configs);
|
|
38
|
-
this.handleAuthRoutes = (configs) => (request, response) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
this.handleAuthRoutes = (configs, onError) => (request, response) => {
|
|
39
|
+
try {
|
|
40
|
+
const { action } = request.query;
|
|
41
|
+
if (action === 'sign-in') {
|
|
42
|
+
return this.handleSignIn()(request, response);
|
|
43
|
+
}
|
|
44
|
+
if (action === 'sign-up') {
|
|
45
|
+
return this.handleSignIn(undefined, 'signUp')(request, response);
|
|
46
|
+
}
|
|
47
|
+
if (action === 'sign-in-callback') {
|
|
48
|
+
return this.handleSignInCallback()(request, response);
|
|
49
|
+
}
|
|
50
|
+
if (action === 'sign-out') {
|
|
51
|
+
return this.handleSignOut()(request, response);
|
|
52
|
+
}
|
|
53
|
+
if (action === 'user') {
|
|
54
|
+
return this.handleUser(configs)(request, response);
|
|
55
|
+
}
|
|
56
|
+
response.status(404).end();
|
|
51
57
|
}
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (onError) {
|
|
60
|
+
return onError(request, response, error);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
54
63
|
}
|
|
55
|
-
response.status(404).end();
|
|
56
64
|
};
|
|
57
65
|
this.withLogtoApiRoute = (handler, config = {}, onError) => async (request, response) => {
|
|
58
66
|
try {
|