Skip to content

Commit deccb9c

Browse files
committed
Code review fixes
1 parent 0c1ecca commit deccb9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3281
-4098
lines changed

examples/with-next-ssr-app-directory/app/actions/serverActionThatLoadsTheSession.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ init(ssrConfig());
88

99
export async function serverActionThatLoadsTheSession() {
1010
const cookiesStore = await cookies();
11-
const session = await getServerActionSession(cookiesStore);
12-
console.log("session", session);
11+
const { status, session } = await getServerActionSession(cookiesStore);
12+
if (status !== "valid") {
13+
// User is not authenticated return early or throw an error
14+
return;
15+
}
16+
17+
// Perform the authenticated action
18+
const userId = session.userId;
19+
console.log("userId", userId);
1320
return Promise.resolve(true);
1421
}

examples/with-next-ssr-app-directory/app/actions/serverActionThatReceivesTheSession.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/with-next-ssr-app-directory/app/components/home.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export async function HomePage() {
3636
<div>Your userID is:</div>
3737
<div className={`${styles.truncate} ${styles.userId}`}>{session.userId}</div>
3838
<CallAPIButton />
39-
<MiddlewareServerActionButton />
4039
<ServerActionButton />
4140
</div>
4241
</div>

examples/with-next-ssr-app-directory/app/components/middlewareServerActionButton.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
"use client";
22

33
import { serverActionThatLoadsTheSession } from "../actions/serverActionThatLoadsTheSession";
4+
import { confirmAuthenticationAndCallServerAction, init } from "supertokens-auth-react/nextjs/ssr";
45
import styles from "../page.module.css";
6+
import { ssrConfig } from "../config/ssr";
7+
8+
init(ssrConfig());
59

610
export const ServerActionButton = () => {
711
return (
812
<div
913
style={{ marginTop: "20px" }}
1014
onClick={async (e) => {
11-
const result = await serverActionThatLoadsTheSession();
12-
console.log(result);
15+
// The wrapper function ensures that the user is authenticated before calling the server action
16+
const result = await confirmAuthenticationAndCallServerAction(serverActionThatLoadsTheSession);
1317
}}
1418
className={styles.sessionButton}
1519
>
16-
Server Action that loads the session
20+
Call Server Action
1721
</div>
1822
);
1923
};

examples/with-next-ssr-app-directory/app/config/backend.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export let backendConfig = (): TypeInput => {
8484
contactMethod: "EMAIL_OR_PHONE",
8585
flowType: "USER_INPUT_CODE_AND_MAGIC_LINK",
8686
}),
87-
SessionNode.init(),
87+
SessionNode.init({
88+
getTokenTransferMethod: () => "header",
89+
}),
8890
Dashboard.init(),
8991
UserRoles.init(),
9092
],

examples/with-next-ssr-app-directory/app/config/frontend.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const frontendConfig = (): SuperTokensConfig => {
3434
PasswordlessReact.init({
3535
contactMethod: "EMAIL_OR_PHONE",
3636
}),
37-
Session.init(),
37+
Session.init({
38+
// tokenTransferMethod: "header"
39+
}),
3840
],
3941
windowHandler: (orig) => {
4042
return {

lib/build/arrowLeftIcon.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/authCompWrapper.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/authRecipe-shared.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)