Swift & Node.js Quickstart
This is a quickstart guide to help you integrate Descope with your Swift & Node.js application. Follow the steps below to get started.
Add the DescopeKit package
Next, we need to add the DescopeKit package (our Swift SDK) using the Swift package manager.
- Within XCode, go to File > Add Packages and search for the URL of the git repo: https://github.com/descope/swift-sdk.
- Then, configure your desired dependency rule and click "Add Package."
Import Frontend SDK
Next step is to import the DescopeKit package
Configure Descope with a custom Project ID
Configure Descope in the scene function of the SceneDelegate.swift. A Descope Project ID is required to initialize the SDK. You can find this ID on the project page in the Descope Console.
Note
You can also add the optional baseUrl
parameter if you're utilizing a CNAME within your Descope project (ex: https://auth.company.com
).
Add the Flow URL
You'll need to get your flowURL, which is the URL where your authentication flow is hosted on the web (eg. https://example.com/login
).
Call the startFlow
function
The 'startFlow' function starts the authentication process with a custom flow url.
Create a UI component to trigger the startFlow
function
Here, we implement a Button that when clicked, calls the start flow function we just wrote.
Utilize the Swift SDK Session Management Functions
Descope provides the sessionManager to check if the user is authenticated or get user data such as email, userId, etc. You can use these to customize the user experience:
isAuthenticated
: is user authenticated?user
: user object that contains all user attributes (email, name, etc.)me
: updates the managed session user details and returns itlogout
: logs the user out by revoking the active session and clearing it from the session manager/Keychain storage
At this point, you're done with the frontend. If you would like to also handle Session Management in your backend, keep on reading!
Import and Setup Backend SDK
You'll need import and setup all of the packages from the SDK.
If you're using a CNAME with your Descope project, make sure to include baseUrl
in the parameters (e.g. {baseUrl : 'https://api.descope.com'}
) when you initialize DescopeClient
.
Implement Session Validation
You will need to then fetch the session token from the Authorization header of each request, and use the SDK to validate the token.
The frontend SDK will store the session token in either a cookie or your browser's local storage. If using a cookie, the token will be sent to your app server automatically with every request.
Congratulations
Now that you've got the authentication down, go focus on building out the rest of your app!
Checkpoint
Your application is now integrated with Descope. Please test with sign-up or sign-in use case.
Customize
Now that you have the end-to-end application working, you can choose to configure and personalize many different areas of Descope, including your brand, style, custom user authentication journeys, etc. We recommend starting with customizing your user-facing screens, such as signup and login.