Skip to content

Commit abea7dd

Browse files
committed
More code simplifications
1 parent 3020e41 commit abea7dd

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

demos/bookstore/app/layout.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ export function Layout({ children }: { children?: Remix.RemixNode }) {
101101
action={routes.auth.logout.href()}
102102
style={{ display: 'inline' }}
103103
>
104-
<button
105-
type="submit"
106-
className="btn btn-secondary"
107-
style={{ marginLeft: '1rem' }}
108-
>
104+
<button type="submit" class="btn btn-secondary" style="margin-left: 1rem;">
109105
Logout
110106
</button>
111107
</form>
@@ -120,10 +116,10 @@ export function Layout({ children }: { children?: Remix.RemixNode }) {
120116
</div>
121117
</header>
122118
<main>
123-
<div className="container">{children}</div>
119+
<div class="container">{children}</div>
124120
</main>
125121
<footer>
126-
<div className="container">
122+
<div class="container">
127123
<p>&copy; {new Date().getFullYear()} Bookstore Demo. Built with Remix.</p>
128124
</div>
129125
</footer>

demos/bookstore/app/middleware/auth.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,11 @@ export function requireAuth(options?: RequireAuthOptions): Middleware {
4242

4343
return async ({ session, url }) => {
4444
let userId = session.get('userId')
45+
let user = typeof userId === 'string' && getUserById(userId)
4546

46-
if (typeof userId !== 'string') {
47-
// Capture the current URL to redirect back after login
48-
let returnTo = url.pathname + url.search
49-
let loginUrl = redirectRoute.href(undefined, { returnTo })
50-
return redirect(loginUrl, 302)
51-
}
52-
53-
let user = getUserById(userId)
5447
if (!user) {
55-
// Capture the current URL to redirect back after login
56-
let returnTo = url.pathname + url.search
57-
let loginUrl = redirectRoute.href(undefined, { returnTo })
58-
return redirect(loginUrl, 302)
48+
// Capture the current URL to redirect back to after login
49+
return redirect(redirectRoute.href(undefined, { returnTo: url.pathname + url.search }), 302)
5950
}
6051

6152
setCurrentUser(user)

0 commit comments

Comments
 (0)