zhefciad
zhefciad
KKinde
Created by zhefciad on 3/31/2024 in #💻┃support
Manually fetch user
Thanks! Exactly what I needed.
5 replies
KKinde
Created by zhefciad on 3/14/2024 in #💻┃support
I'm getting a bunch of api/auth xhr requests, is this normal?
I found the culprit. I'm rendering a bunch of cards and I accidentally left an unused useKindeBrowserClient hook. All good now. Thanks guys
6 replies
KKinde
Created by zhefciad on 3/14/2024 in #💻┃support
I'm getting a bunch of api/auth xhr requests, is this normal?
Thanks!
6 replies
KKinde
Created by zhefciad on 3/14/2024 in #💻┃support
I'm getting a bunch of api/auth xhr requests, is this normal?
If it's not, then it's probably something I did in my end.
6 replies
KKinde
Created by zhefciad on 3/14/2024 in #💻┃support
I'm getting a bunch of api/auth xhr requests, is this normal?
NextJS v2
6 replies
KKinde
Created by zhefciad on 3/14/2024 in #💻┃support
Add clickable button that redirects them back into the homepage when on authentication page
Not really, but would love to have it for better UX in the future
7 replies
KKinde
Created by zhefciad on 2/24/2024 in #💻┃support
Custom Success route.ts failing in build process && not showing logs inside GET()
I solved it by moving the user creation logic in the frontend. But if there's any way to build the file as a server side code without any errors, please let me know.
8 replies
KKinde
Created by zhefciad on 2/24/2024 in #💻┃support
Custom Success route.ts failing in build process && not showing logs inside GET()
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextResponse } from "next/server";
import axios from "axios";


const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://127.0.0.1:1337";
const baseFrontendUrl =
process.env.NEXT_PUBLIC_FRONTEND_URL || "http://localhost:3000";

console.log("Test 1")

GET();

export async function GET() {
console.log("Test 2")
const { getUser } = getKindeServerSession();
const user = await getUser();
console.log("User from Kinde:", user);

try {
if (user) {
console.log("Test 3")
const dbUserResponse = await axios.get(
`${baseUrl}/api/kinde-users?filters[kindeID][$eq]=${user.id}`
);
console.log("dbUserResponse:", dbUserResponse.data);

if (!dbUserResponse.data.data || dbUserResponse.data.data.length === 0) {
console.log("Test 4")
const newUserResponse = await axios.post(baseUrl + "/api/kinde-users", {
data: {
kindeID: user.id,
firstName: user.given_name ?? "",
lastName: user.family_name ?? "",
email: user.email ?? "",
picture: user.picture ?? "",
},
});
console.log("New user created:", newUserResponse.data);
}
}

return NextResponse.redirect(baseFrontendUrl);
} catch (error) {
console.error("Error interacting with Strapi:", error);
throw new Error("Failed to interact with Strapi");
}
}
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextResponse } from "next/server";
import axios from "axios";


const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://127.0.0.1:1337";
const baseFrontendUrl =
process.env.NEXT_PUBLIC_FRONTEND_URL || "http://localhost:3000";

console.log("Test 1")

GET();

export async function GET() {
console.log("Test 2")
const { getUser } = getKindeServerSession();
const user = await getUser();
console.log("User from Kinde:", user);

try {
if (user) {
console.log("Test 3")
const dbUserResponse = await axios.get(
`${baseUrl}/api/kinde-users?filters[kindeID][$eq]=${user.id}`
);
console.log("dbUserResponse:", dbUserResponse.data);

if (!dbUserResponse.data.data || dbUserResponse.data.data.length === 0) {
console.log("Test 4")
const newUserResponse = await axios.post(baseUrl + "/api/kinde-users", {
data: {
kindeID: user.id,
firstName: user.given_name ?? "",
lastName: user.family_name ?? "",
email: user.email ?? "",
picture: user.picture ?? "",
},
});
console.log("New user created:", newUserResponse.data);
}
}

return NextResponse.redirect(baseFrontendUrl);
} catch (error) {
console.error("Error interacting with Strapi:", error);
throw new Error("Failed to interact with Strapi");
}
}
I run the GET() manually and it somehow worked, I can now see console logs after success inside the GET() function. The problem is it's not getting any user. This is the log
Test 1
Test 2
User from Kinde: null
Test 1
Test 2
User from Kinde: null
8 replies
KKinde
Created by zhefciad on 2/24/2024 in #💻┃support
Custom Success route.ts failing in build process && not showing logs inside GET()
src > app > api > auth > success > route.ts:
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextResponse } from "next/server";
import axios from "axios";
console.log("TEST 1");
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://127.0.0.1:1337";
const baseFrontendUrl = process.env.NEXT_PUBLIC_FRONTEND_URL || "http://localhost:3000";

console.log("TEST 2");
export async function GET() {
const { getUser } = getKindeServerSession();
const user = await getUser();
console.log("User from Kinde:", user);
console.log("TEST 3");
if (process.env.NEXT_PUBLIC_BUILD_TIME) {
console.log("Skipping user authentication during build.");
return NextResponse.redirect(baseFrontendUrl);
}
console.log("TEST 4");
if (!user || user == null || !user.id)
throw new Error(
"Something went wrong with authentication: " + JSON.stringify(user)
);
console.log("TEST 5");
try {
const dbUserResponse = await axios.get(
`${baseUrl}/api/kinde-users?filters[kindeID][$eq]=${user.id}`
);
console.log("dbUserResponse:", dbUserResponse.data);
console.log("TEST 6");
if (!dbUserResponse.data.data || dbUserResponse.data.data.length === 0) {
const newUserResponse = await axios.post(baseUrl + "/api/kinde-users", {
data: {
kindeID: user.id,
firstName: user.given_name ?? "",
lastName: user.family_name ?? "",
email: user.email ?? "",
picture: user.picture ?? "",
},
});
console.log("New user created:", newUserResponse.data);
}
console.log("TEST 7");
return NextResponse.redirect(baseFrontendUrl);
} catch (error) {
console.log("TEST 8");
console.error("Error interacting with Strapi:", error);
throw new Error("Failed to interact with Strapi");
}
}
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextResponse } from "next/server";
import axios from "axios";
console.log("TEST 1");
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://127.0.0.1:1337";
const baseFrontendUrl = process.env.NEXT_PUBLIC_FRONTEND_URL || "http://localhost:3000";

console.log("TEST 2");
export async function GET() {
const { getUser } = getKindeServerSession();
const user = await getUser();
console.log("User from Kinde:", user);
console.log("TEST 3");
if (process.env.NEXT_PUBLIC_BUILD_TIME) {
console.log("Skipping user authentication during build.");
return NextResponse.redirect(baseFrontendUrl);
}
console.log("TEST 4");
if (!user || user == null || !user.id)
throw new Error(
"Something went wrong with authentication: " + JSON.stringify(user)
);
console.log("TEST 5");
try {
const dbUserResponse = await axios.get(
`${baseUrl}/api/kinde-users?filters[kindeID][$eq]=${user.id}`
);
console.log("dbUserResponse:", dbUserResponse.data);
console.log("TEST 6");
if (!dbUserResponse.data.data || dbUserResponse.data.data.length === 0) {
const newUserResponse = await axios.post(baseUrl + "/api/kinde-users", {
data: {
kindeID: user.id,
firstName: user.given_name ?? "",
lastName: user.family_name ?? "",
email: user.email ?? "",
picture: user.picture ?? "",
},
});
console.log("New user created:", newUserResponse.data);
}
console.log("TEST 7");
return NextResponse.redirect(baseFrontendUrl);
} catch (error) {
console.log("TEST 8");
console.error("Error interacting with Strapi:", error);
throw new Error("Failed to interact with Strapi");
}
}
8 replies
KKinde
Created by zhefciad on 2/24/2024 in #💻┃support
Custom Success route.ts failing in build process && not showing logs inside GET()
Logs from npm run build on prod:
./src/app/api/auth/success/route.ts:30:59
Type error: 'user' is possibly 'null'.

28 | console.log("new user created")
29 | const dbUserResponse = await axios.get(
> 30 | `${baseUrl}/api/kinde-users?filters[kindeID][$eq]=${user.id}`
| ^
31 | );
32 | console.log("dbUserResponse:", dbUserResponse.data);
33 | console.log("TEST 6");
Linting and checking validity of types ...root@srv478287:/var/www/reelist8-master/frontend/src/app/api/auth/success#
./src/app/api/auth/success/route.ts:30:59
Type error: 'user' is possibly 'null'.

28 | console.log("new user created")
29 | const dbUserResponse = await axios.get(
> 30 | `${baseUrl}/api/kinde-users?filters[kindeID][$eq]=${user.id}`
| ^
31 | );
32 | console.log("dbUserResponse:", dbUserResponse.data);
33 | console.log("TEST 6");
Linting and checking validity of types ...root@srv478287:/var/www/reelist8-master/frontend/src/app/api/auth/success#
```
8 replies