November 2018
Intermediate to advanced
404 pages
10h 16m
English
To display different messages in a template according to the authentication state, you can pass a Boolean value via the Encodable context to your Leaf template.
Add the isAdmin Boolean to JournalContext:
struct JournalContext : Encodable { let isAdmin: Bool let title: String let author: String let count: String let entries: [JournalEntry]}
In the header.leaf template, you use isAdmin to display different options for the user. When the user is not authenticated, you want to display a link that allows the user to login; otherwise, display the logout link for an authenticated user to exit the session:
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>#(title)</title><!-- Required meta tags --> ...
Read now
Unlock full access