Skip to content

Commit d06fcfc

Browse files
committed
remove _isAction and fix types
1 parent f8e5af2 commit d06fcfc

File tree

1 file changed

+15
-37
lines changed
  • packages/auth-solid-start/src/server

1 file changed

+15
-37
lines changed

packages/auth-solid-start/src/server/index.ts

+15-37
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface CreateAuthRouteHandlers {
6464
provider: BuiltinOAuthProviderNames;
6565
isSignUp: boolean;
6666
}>,
67-
): Promise<never>;
67+
): Promise<never | Response>;
6868
onEmailPasswordSignIn(
6969
params: ParamsOrError<{ tokenData: TokenData }>,
7070
): Promise<Response>;
@@ -79,19 +79,19 @@ export interface CreateAuthRouteHandlers {
7979
{ tokenData: TokenData },
8080
{ verificationToken?: string }
8181
>,
82-
): Promise<never>;
82+
): Promise<never | Response>;
8383
onWebAuthnSignUp(
8484
params: ParamsOrError<{ tokenData: TokenData | null }>,
8585
): Promise<Response>;
8686
onWebAuthnSignIn(
8787
params: ParamsOrError<{ tokenData: TokenData }>,
88-
): Promise<never>;
88+
): Promise<never | Response>;
8989
onMagicLinkCallback(
9090
params: ParamsOrError<{ tokenData: TokenData; isSignUp: boolean }>,
91-
): Promise<never>;
91+
): Promise<never | Response>;
9292
onMagicLinkSignIn(
9393
params: ParamsOrError<{ tokenData: TokenData }>,
94-
): Promise<never>;
94+
): Promise<never | Response>;
9595
onBuiltinUICallback(
9696
params: ParamsOrError<
9797
(
@@ -105,8 +105,8 @@ export interface CreateAuthRouteHandlers {
105105
}
106106
) & { isSignUp: boolean }
107107
>,
108-
): Promise<never>;
109-
onSignout(evt: APIEvent): Promise<never>;
108+
): Promise<never | Response>;
109+
onSignout(evt: APIEvent): Promise<never | Response>;
110110
}
111111

112112
export class SolidServerAuth extends SolidAuthHelpers {
@@ -142,7 +142,6 @@ export class SolidServerAuth extends SolidAuthHelpers {
142142

143143
setAuthCookie(token: string) {
144144
const expirationDate = Auth.getTokenExpiration(token);
145-
146145
setCookie(this.options.authCookieName, token, {
147146
httpOnly: true,
148147
path: "/",
@@ -473,8 +472,7 @@ export class SolidServerAuth extends SolidAuthHelpers {
473472
switch (evt.params.auth) {
474473
case "emailpassword/signin": {
475474
const data = await _getReqBody(req);
476-
const isAction = _isAction(data);
477-
if (!isAction && !onEmailPasswordSignIn) {
475+
if (!onEmailPasswordSignIn) {
478476
throw new ConfigurationError(
479477
`'onEmailPasswordSignIn' auth route handler not configured`,
480478
);
@@ -500,8 +498,7 @@ export class SolidServerAuth extends SolidAuthHelpers {
500498
}
501499
case "emailpassword/signup": {
502500
const data = await _getReqBody(req);
503-
const isAction = _isAction(data);
504-
if (!isAction && !onEmailPasswordSignUp) {
501+
if (!onEmailPasswordSignUp) {
505502
throw new ConfigurationError(
506503
`'onEmailPasswordSignUp' auth route handler not configured`,
507504
);
@@ -546,7 +543,6 @@ export class SolidServerAuth extends SolidAuthHelpers {
546543
);
547544
}
548545
const data = await _getReqBody(req);
549-
const isAction = _isAction(data);
550546
const [email] = _extractParams(
551547
data,
552548
["email"],
@@ -562,14 +558,11 @@ export class SolidServerAuth extends SolidAuthHelpers {
562558
).toString(),
563559
);
564560
this.setVerifierCookie(verifier);
565-
return isAction
566-
? Response.json({ _data: null })
567-
: new Response(null, { status: 204 });
561+
return Response.json({ _data: null });
568562
}
569563
case "emailpassword/reset-password": {
570564
const data = await _getReqBody(req);
571-
const isAction = _isAction(data);
572-
if (!isAction && !onEmailPasswordReset) {
565+
if (!onEmailPasswordReset) {
573566
throw new ConfigurationError(
574567
`'onEmailPasswordReset' auth route handler not configured`,
575568
);
@@ -600,7 +593,6 @@ export class SolidServerAuth extends SolidAuthHelpers {
600593
}
601594
case "emailpassword/resend-verification-email": {
602595
const data = await _getReqBody(req);
603-
const isAction = _isAction(data);
604596
const verificationToken =
605597
data instanceof FormData
606598
? data.get("verification_token")?.toString()
@@ -614,9 +606,7 @@ export class SolidServerAuth extends SolidAuthHelpers {
614606
await (
615607
await this.core
616608
).resendVerificationEmail(verificationToken.toString());
617-
return isAction
618-
? Response.json({ _data: null })
619-
: new Response(null, { status: 204 });
609+
return Response.json({ _data: null });
620610
} else if (email) {
621611
const { verifier } = await (
622612
await this.core
@@ -629,9 +619,7 @@ export class SolidServerAuth extends SolidAuthHelpers {
629619
sameSite: "strict",
630620
path: "/",
631621
});
632-
return isAction
633-
? Response.json({ _data: null })
634-
: new Response(null, { status: 204 });
622+
return Response.json({ _data: null });
635623
} else {
636624
throw new InvalidDataError(
637625
"verification_token or email missing from request body",
@@ -697,7 +685,6 @@ export class SolidServerAuth extends SolidAuthHelpers {
697685
);
698686
}
699687
const data = await _getReqBody(req);
700-
const isAction = _isAction(data);
701688
const [email] = _extractParams(
702689
data,
703690
["email"],
@@ -714,9 +701,7 @@ export class SolidServerAuth extends SolidAuthHelpers {
714701
).toString(),
715702
);
716703
this.setVerifierCookie(verifier);
717-
return isAction
718-
? Response.json({ _data: null })
719-
: new Response(null, { status: 204 });
704+
return Response.json({ _data: null });
720705
}
721706
case "magiclink/send": {
722707
if (!this.options.magicLinkFailurePath) {
@@ -725,7 +710,6 @@ export class SolidServerAuth extends SolidAuthHelpers {
725710
);
726711
}
727712
const data = await _getReqBody(req);
728-
const isAction = _isAction(data);
729713
const [email] = _extractParams(
730714
data,
731715
["email"],
@@ -742,9 +726,7 @@ export class SolidServerAuth extends SolidAuthHelpers {
742726
).toString(),
743727
);
744728
this.setVerifierCookie(verifier);
745-
return isAction
746-
? Response.json({ _data: null })
747-
: new Response(null, { status: 204 });
729+
return Response.json({ _data: null });
748730
}
749731
default:
750732
return new Response("Unknown auth route", {
@@ -954,10 +936,6 @@ function _getReqBody(
954936
: req.formData();
955937
}
956938

957-
function _isAction(data: any) {
958-
return typeof data === "object" && data._action === true;
959-
}
960-
961939
function _wrapError(err: Error) {
962940
return {
963941
_error: {

0 commit comments

Comments
 (0)