Skip to content

Commit

Permalink
Fix: Fixed Function Definitions and Access Modifiers (#31)
Browse files Browse the repository at this point in the history
* RELEASE

* added changes

* added files

* added changes

* simplified functions

* fixed function defintions

* added files

* fixed linter

* fixed linter

* fixed linter

* fixed search

* reverted some breaking changes

* fixed linter
  • Loading branch information
gaokevin1 authored Nov 1, 2024
1 parent 9b6a204 commit bf29968
Show file tree
Hide file tree
Showing 23 changed files with 1,429 additions and 871 deletions.
28 changes: 18 additions & 10 deletions sample/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@
echo "Descope Project ID not present. Please check .env file.";
exit(1);
}

$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['DESCOPE_PROJECT_ID']
]);

if (isset($_POST["sessionToken"]) && $descopeSDK->verify($_POST["sessionToken"])) {
$_SESSION["user"] = json_decode($_POST["userDetails"], true);
$_SESSION["sessionToken"] = $_POST["sessionToken"];

session_write_close();

// Redirect to dashboard
header('Location: dashboard.php');
exit();
if (isset($_POST["sessionToken"])) {
if ($descopeSDK->verify($_POST["sessionToken"])) {
$_SESSION["user"] = json_decode($_POST["userDetails"], true);
$_SESSION["sessionToken"] = $_POST["sessionToken"];
session_write_close();

// Redirect to dashboard
header('Location: dashboard.php');
exit();
} else {
error_log("Session token verification failed.");
$descopeSDK->logout();
// Redirect to login page
header('Location: login.php');
exit();
}
} else {
error_log("Session token is not set in POST request.");
// Redirect to login page
header('Location: login.php');
exit();
Expand Down
18 changes: 3 additions & 15 deletions sample/dashboard.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
<?php
// session_start();

require '../vendor/autoload.php';
use Descope\SDK\DescopeSDK;

session_start();

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();

if (!isset($_ENV['DESCOPE_PROJECT_ID'])) {
echo "Descope Project ID not present. Please check .env file.";
exit(1);
}
session_start();

$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['DESCOPE_PROJECT_ID']
]);
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();

if (!isset($_SESSION["user"])) {
session_destroy();
Expand Down
23 changes: 21 additions & 2 deletions sample/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,32 @@ function sendFormData(sessionToken, userDetails) {
return user;
}
async function handleLogout() {
}
async function handleLogin() {
try {
// Wait for refresh to ensure token validity
console.log("Attempting to refresh the session...");
await sdk.refresh();
const sessionToken = sdk.getSessionToken();
console.log("Session token obtained:", sessionToken);
if (!sessionToken) {
console.log("Session token is missing after refresh. Redirecting to login.");
window.location.href = 'login.php'; // Redirect to login if session token is invalid
return;
}
const user = await getUserDetails();
console.log("User details obtained:", user);
sendFormData(sessionToken, user.data);
} catch (error) {
console.log("Error during login:", error);
sdk.logout();
window.location.href = 'login.php'; // Redirect to login on error
}
}
Expand All @@ -57,15 +73,18 @@ function sendFormData(sessionToken, userDetails) {
console.log("Valid refresh token found. Logging in...");
handleLogin();
} else {
sdk.logout();
console.log("No valid refresh token. Displaying login form.");
const container = document.getElementById("container")
container.innerHTML = '<descope-wc project-id="' + projectId + '" flow-id="sign-up-or-in"></descope-wc>';
const wcElement = document.getElementsByTagName('descope-wc')[0];
const onSuccess = async (e) => {
console.log("Login successful, handling login.");
await handleLogin(); // Wait for login and session details
}
const onError = (err) => console.log(err);
const onError = (err) => console.log("Login error:", err);
if (wcElement) {
wcElement.addEventListener('success', onSuccess);
Expand Down
Loading

0 comments on commit bf29968

Please sign in to comment.