Skip to content

Commit 5bfbbd1

Browse files
committed
check server actions
1 parent 0797deb commit 5bfbbd1

File tree

14 files changed

+248
-98
lines changed

14 files changed

+248
-98
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use server";
2+
3+
import { cookies } from "next/headers";
4+
import { redirect } from "next/navigation";
5+
import { getServerComponentSession, getServerActionSession, init } from "supertokens-auth-react/nextjs/ssr";
6+
import { ssrConfig } from "../config/ssr";
7+
8+
init(ssrConfig());
9+
10+
export async function checkSSRSession(e) {
11+
const cookiesStore = await cookies();
12+
// const session = await getServerComponentSession(cookiesStore);
13+
const session = await getServerActionSession(cookiesStore);
14+
15+
console.log(session);
16+
return Promise.resolve(true);
17+
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import { CallAPIButton } from "./callApiButton";
77
import { LinksComponent } from "./linksComponent";
88
import { SessionAuthForNextJS } from "./sessionAuthForNextJS";
99

10-
import { getSSRSession, init } from "supertokens-auth-react/nextjs/ssr";
10+
import { getServerComponentSession, init } from "supertokens-auth-react/nextjs/ssr";
1111
import { ssrConfig } from "../config/ssr";
12+
import { useState } from "react";
13+
import { SSRButton } from "./ssrButton";
1214

1315
init(ssrConfig());
1416

1517
export async function HomePage() {
1618
const cookiesStore = await cookies();
17-
const session = await getSSRSession(cookiesStore, redirect);
18-
console.log(session);
19+
const session = await getServerComponentSession(cookiesStore);
20+
console.log(session.userId);
1921

2022
/**
2123
* SessionAuthForNextJS will handle proper redirection for the user based on the different session states.
@@ -33,6 +35,7 @@ export async function HomePage() {
3335
<div>Your userID is:</div>
3436
<div className={`${styles.truncate} ${styles.userId}`}>{session.userId}</div>
3537
<CallAPIButton />
38+
<SSRButton />
3639
</div>
3740
</div>
3841
<LinksComponent />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client";
2+
3+
import { checkSSRSession } from "../actions/checkSSRSession";
4+
import styles from "../page.module.css";
5+
6+
export const SSRButton = () => {
7+
return (
8+
<div
9+
style={{ marginTop: "20px" }}
10+
onClick={async (e) => {
11+
await checkSSRSession(e);
12+
}}
13+
className={styles.sessionButton}
14+
>
15+
Check SSR Session
16+
</div>
17+
);
18+
};

lib/build/constants.js

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

lib/build/nextjs/constants.d.ts

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

lib/build/nextjs/middleware.d.ts

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/nextjs/ssr.d.ts

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

lib/build/nextjs/types.d.ts

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

lib/build/nextjsmiddleware.js

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

lib/build/nextjsssr.js

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

lib/ts/nextjs/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export const REDIRECT_ATTEMPT_COUNT_COOKIE_NAME = "sSsrSessionRefreshAttempt";
1111
export const CURRENT_PATH_COOKIE_NAME = "sCurrentPath";
1212
export const FORCE_LOGOUT_PATH_PARAM_NAME = "forceLogout";
1313
export const REDIRECT_PATH_PARAM_NAME = "stRedirectTo";
14+
export const SESSION_REFRESH_API_PATH = "/api/auth/session/refresh";

0 commit comments

Comments
 (0)