Swiftpack.co - GetStream/stream-chat-vapor-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GetStream.
GetStream/stream-chat-vapor-swift 0.1.0
Stream Chat Vapor integration libary
⭐️ 10
🕓 1 year ago
macOS linux macOS iOS
.package(url: "https://github.com/GetStream/stream-chat-vapor-swift.git", from: "0.1.0")

StreamChat Vapor Swift Backend

This library contains the code to integrate client applications with Stream's backend using Vapor Swift. It also contains an example application demonstrating how to integrate the library with a Vapor applications.

Integrating the libray

Add the library as a dependency to your Package.swift:

dependencies: [
    // ...
    .package(name: "StreamChat", url: "https://github.com/GetStream/stream-chat-vapor-swift.git", from: "0.1.0"),
],

Then add the the dependency to your application, e.g.:

.target(
    name: "App",
    dependencies: [
        .product(name: "StreamSDKVapor", package: "StreamChat"),
        // ...
    ],
    // ...

Configuration

The Stream library requires your Stream access key and access secret to work. Configure the libray as so:

// Get the keys, for example from environment variables
guard let streamAccessKey = Environment.get("STREAM_ACCESS_KEY"), let streamAccessSecret = Environment.get("STREAM_ACCESS_SECRET") else {
    app.logger.critical("STREAM keys not set")
    fatalError("STREAM keys not set")
}

let streamConfig = StreamConfiguration(accessKey: streamAccessKey, accessSecret: streamAccessSecret)
app.stream.use(streamConfig)

Generating a JWT

To generate a JWT to use with Stream's backend you need the user ID. You can then call the Stream library to generate the token:

let streamToken = try req.stream.createToken(name: userID)

You can pass an optional date for the token to expire at as well:

let streamToken = try req.stream.createToken(name: userID, expiresAt: Date().addingTimeInterval(3600))

Running the sample application

To get started you need to do a couple things:

  • Install Docker Desktop.
  • Run ./scripts/localDockerDB.swift start
  • open Package.swift
  • Set working dir of scheme in Xcode to root of project.
  • Run project

The application allows users to register traditionally by sending a POST request to /auth/register and also using Sign In With Apple.

When registering or logging in the Vapor app returns both an API key for interacting with the API as the authenticated user and also a JWT for use with Stream's backend.

More example code

See these supporting repositories to see how integrating this libary would look in your codebase:

Blog article

We also have a blog article describing what is in this repository and how to get started.

GitHub

link
Stars: 10
Last commit: 48 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.1.0
1 year ago

Initial release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics