Creating a server using vapor and having issues

ok I am clueless! I have been trying to create a server for an app im building using vapor, I have been using chat GPT to help build it. I keep coming up against signer errors. that being said I have discovered you can download template server but although it successfully built when I run the server I was hit with a crash and a fatal error. im look gin for advice on a good template to download and best way to set up. thanks in advance

The best place to start would be the docs - Vapor: Getting Started → Hello, world

The template offered by the toolbox is the recommended way to give you what you need. So vapor new MyProject and follow the prompts. If you hit errors, it would be good to know what they are

thank you I will give it a look now

Another tutorial series I created is on YouTube! (On CodeWithChris channel, but I’ll be doing an update on my own YouTube channel later)

It uses closures (but then at the end is a video about updating to async await syntax)

3 Likes

thank you I have had a little look at this and it has been very helpful any many respects

I have been battling getting a server up and running as I have very little knowledge I have used chat GPT to help me build it. Much progress has been made but now we have reached a point where we are using JWT and I have been up against a brick wall with this and not even chat GPT is coming up with any decent solutions what am I likely to be doing wrong? the screen shot is now just part of a minimalist version to see if I can troubleshoot what’s happening but the same faults have appeared in the tiny project in the same way that it has in my overall bigger project

It's a bad error, but the "Cannot infer contextual base..." usually shows up either when the compiler is confused about other errors (doesn't look like it in this case) or because the static accessor you're using is incorrect in some way. In this case, are you sue .hs256 is the proper name? You can also click the error to see what other error it says it found, since there's a 2 next to it.

These are the two errors, ChatGPT says '“Those two errors mean Xcode doesn’t see JWTKit attached to your app target (so Application.jwt and .hs256 don’t exist). It’s almost never the code inside Configure.swift; it’s the package wiring.” and then proceeds to provide a non fix!

Yes, you need to investigate both errors. See whether App actually has a jwt property, and see what type use takes as a parameter and see whether hs256 exists.

ok than you I will try fumble through

You need to import (or add a dependency) on JWT not JWTKit - JWT contains the extension on Application for the jwt property. Without importing that, the compiler can’t see it

Hi so in my package dependencies I can see JWT and JWT-Kit

then in my package.swift I have it in dependencies

Is that what you’re feeding to?

In the file configure.swift you’re importing JWTKit. You need to change it to import JWT

Also, it looks like you're using older versions of both Vapor and JWTKit. If you want to update, you can check out the API for JWTKit 5 at GitHub - vapor/jwt-kit: 🔑 JSON Web Token (JWT) signing and verification (HMAC, ECDSA, EdDSA, MLDSA, RSA, PSS) with support for JWS and JWK and Vapor: Security → JWT but note that it uses async-coloured code, this means that to use it, you’ll also need to update Vapor to use the asynchronous configure method. And if you're using a non-async configure, it’s likely that your entrypoint.swift is also from an older version. If needed you can check out GitHub - vapor/template: Used by Vapor Toolbox’s new project command to view the updated versions of both.