Skip to content

Commit

Permalink
feat: improve API and README (#40)
Browse files Browse the repository at this point in the history
* feat: silentSignin

* feat: add README.md for slient login

* feat: enhance README.md

* feat:fix readme
  • Loading branch information
jakiuncle authored Mar 2, 2023
1 parent fea35ee commit 7b28442
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,22 @@ signin(serverUrl, signinPath)

Handle the callback url from casdoor, call the back-end api to complete the login process

#### Judge whether the silent login is successful
#### Determine whether silent sign-in is being used

```typescript
isSilentSigninRequired()
isSilentSigninRequested()
```

We usually use this method to determine if silent login is being used. By default, if the silentSignin parameter is included in the URL and equals one, this method will return true. Of course, you can also use any method you prefer.

#### silentSignin


````typescript
silentSignin(isLoggedIn, onSuccess, onFailure)
silentSignin(onSuccess, onFailure)
````

if isLoggedIn == false, It will log in silently. If the silent login succeeds,the onSuccess will be executed,else the onFailure will be executed.
First, let's explain the two parameters of this method, which are the callback methods for successful and failed login. Next, I will describe the execution process of this method. We will create a hidden "iframe" element to redirect to the login page for authentication, thereby achieving the effect of silent sign-in.

## More examples

Expand Down
8 changes: 2 additions & 6 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class Sdk {
}).then(res => res.json());
}

public isSilentSigninRequired(): boolean{
public isSilentSigninRequested(): boolean{
const params = new URLSearchParams(window.location.search);
return params.get("silentSignin") === "1";
}

public silentSignin(isLoggedIn: boolean, onSuccess: (message: any) => void, onFailure: (message: any) => void) {
public silentSignin(onSuccess: (message: any) => void, onFailure: (message: any) => void) {
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = `${this.getSigninUrl()}&silentSignin=1`;
Expand All @@ -138,10 +138,6 @@ class Sdk {
if (window !== window.parent) {
return null;
}

if (isLoggedIn){
return null;
}

const message = event.data;
if (message.tag !== "Casdoor" || message.type !== "SilentSignin") {
Expand Down

0 comments on commit 7b28442

Please sign in to comment.