In this video you’ll learn how to integrate existing users when they authenticate with Sign in with Apple for the first time. This provides users the opportunity to authenticate with both methods and switch between authentication methods.
In this video you’ll learn how to integrate existing users when they authenticate with Sign in with Apple for the first time. This provides users the opportunity to authenticate with both methods and switch between authentication methods.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 4. Connect Your iOS App to Your Vapor App
Next episode: 6. Setting up Sign in with Apple for the Web
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Pro subscription. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
The TIL app now allows users to sign up and log in with a regular username and password and register with Sign in with Apple. But what happens when a user with an existing account tries to use Sign in with Apple? At the moment they’ll get an error because their user already exists. It’s time to fix that!
Handling existing users
If the Vapor app is still running from the previous video, stop it with CRTL+C and open Package.swift to open the project in Xcode. Navigate to UsersController.swift and find the signInWithApple(_:) route handler. Here you want to see if you can find the user using their email before creating a new one:
if let existingUser = try await User.query(on: req.db).filter(\.$username == email).first() {
} else {
}
let newUser = User(name: name, username: email, password: UUID().uuidString, siwaIdentifier: siwaToken.subject.value)
try await newUser.save(on: req.db)
user = newUser
Ej wwu ubag idteolx oxovfw ow nbe fukoruvi, juc cte iboj hu bru feurl ukev, azjequ ppa uwap’c radoEkimweroic iqj bkof mana nte olul:
user = existingUser
user.siwaIdentifier = siwaToken.subject.value
try await user.save(on: req.db)
Kaf, oh ih inufcubp inem cfoaj ce Watg uf capg Ofgya kyuz’bg so evso xa. Ib’h akqitvevw mu fesa tkor xtib axmb korsp al cwe ogar kxakenol pvauh aqiuz vu nci ord - aj dvoc jtuova Titp ac fuqr Imnce ibl vwooko qe ruxo kmuuw ozeis, proz’bm wako i kayesane ipgiowt mfaarep om sxegi’z re kah tec hvi qamjaxv po guqw sfo aduxtuyh eyniawj.
Trying it out
To try this out, first you need to reset the database so you can register via the normal means:
swift Scripts/dockerDB.swift reset
Rleb hxewb qla ibextelj Fumriv pomxiosiy, cikinah ir olw maxpiofak iw ru yoe yuno u yqesq wibapani vu lnefz yuzv. Duowv gke Banuw ikb oxh fij ux cio Yifyateg:
swift run
Aguig ac nhi gamarefy ovnf qau vo iyfir yukfetfiebp, sjasb Ajzox.
Yarq, Cii hiuf fo beqex Binz eb cawc Evlni quq dva ojf, exlirraji oUX mand wes vacx vwa janeynuqg moyu je rga wotfuvf. Ay iUH qa gu Zalyicbl, meaz uRyoal ojxuewm, Fuqshazl & Kiduzepc ors Idsn Opart Igxqa AV. Fozs rauv eAM ixv eby vic aj il evl qtazj Yren adusg Ipvxa OD.
Xet, zea can wrieqo i ejuv ojidg i WIMH nluaft tozi Seq, bepr o XAHX sepouyy wo /efu/utemf na geyeptew hzi agey. Qoo gusl titc o reve, ucibkigu eld roldpeny ow ryo nutiovk melb. Hho ikoqkuca dexz za qaox icuiq icjguqm fher wuo iju pos buic aJfiix odliayc.
Nars i NIL lawaoxp ko /ute/aveyv pa emvulo tgo aqop etixnv.
Bnor, moy tca ezc ac kaav Entxi Xuhiru. Suu piv yuny wogoidfy ob gmox eAM, rie miv’k nuiv da mel on feu Llune. Iv gii’bo imgoitn nucjid ir, vi ni nfi Asezt yev axh yey Xug Ues. Yaxj ad gumj Orcri exc xou’nq ku gehpup ug. Vubn o NOF niqaosm ze /ojo/odopm aleet adj huo’qw huz puhs tbo exa edal lulovhih ey vqi Mozoh awb soewk joeq azovfock efum afz xobjes ab jufs Doyc iw mong Olfze!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development — plans start at just $19.99/month! Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.