···
// Update the session cookie
session.did = oauth.session.did
101
-
// Redirect to the homepage
102
-
return res.redirect('/')
ctx.logger.error({ err }, 'oauth callback failed')
return res.redirect('/?error')
104
+
return res.redirect('/')
113
-
handler((req: Request, res: Response) => {
111
+
handler(async (req: Request, res: Response) => {
res.type('html').send(page(login({})))
···
res.type('html').send(page(login({ error: 'invalid input' })))
129
+
// @NOTE input can be a handle, a DID or a service URL (PDS).
// Initiate the OAuth flow
···
handler(async (req: Request, res: Response) => {
205
-
const error = ifString(req.query.error)
// If the user is signed in, get an agent which communicates with their server
const agent = await getSessionAgent(req, res, ctx)
···
// Serve the logged-out view
243
-
res.type('html').send(page(home({ error, statuses, didHandleMap })))
241
+
res.type('html').send(page(home({ statuses, didHandleMap })))
···
// Serve the logged-in view
268
-
.send(page(home({ error, statuses, didHandleMap, profile, myStatus })))
264
+
res.type('html').send(
···
// If the user is signed in, get an agent which communicates with their server
const agent = await getSessionAgent(req, res, ctx)
280
-
res.redirect(`/login}`)
285
+
res.redirect(`/login`)
285
-
const status = req.body?.status
286
-
if (typeof status !== 'string' || !STATUS_OPTIONS.includes(status)) {
287
-
throw new Error('Invalid status')
289
+
const status = ifString(req.body?.status)
290
+
if (!status || !STATUS_OPTIONS.includes(status)) {
291
+
throw new Error('Invalid status')
290
-
// Construct & validate their status record
291
-
const rkey = TID.nextStr()
293
-
$type: 'xyz.statusphere.status',
295
-
createdAt: new Date().toISOString(),
294
+
// Construct & validate their status record
295
+
const rkey = TID.nextStr()
297
+
$type: 'xyz.statusphere.status',
299
+
createdAt: new Date().toISOString(),
298
-
if (!Status.validateRecord(record).success) {
299
-
res.status(400).type('html').send('<h1>Error: Invalid status</h1>')
303
-
// Write the status record to the user's repository
306
-
const res = await agent.com.atproto.repo.putRecord({
307
-
repo: agent.assertDid,
308
-
collection: 'xyz.statusphere.status',
315
-
ctx.logger.error({ err }, 'failed to write record')
319
-
.send('<h1>Error: Failed to write record</h1>')
302
+
if (!Status.validateRecord(record).success) {
303
+
res.status(400).type('html').send('<h1>Error: Invalid status</h1>')
324
-
// Optimistically update our SQLite
325
-
// This isn't strictly necessary because the write event will be
326
-
// handled in #/firehose/ingestor.ts, but it ensures that future reads
327
-
// will be up-to-date after this method finishes.
329
-
.insertInto('status')
332
-
authorDid: agent.assertDid,
333
-
status: record.status,
334
-
createdAt: record.createdAt,
335
-
indexedAt: new Date().toISOString(),
341
-
'failed to update computed view; ignoring as it should be caught by the firehose',
307
+
// Write the status record to the user's repository
310
+
const res = await agent.com.atproto.repo.putRecord({
311
+
repo: agent.assertDid,
312
+
collection: 'xyz.statusphere.status',
319
+
ctx.logger.warn({ err }, 'failed to write record')
323
+
.send('<h1>Error: Failed to write record</h1>')
328
+
// Optimistically update our SQLite
329
+
// This isn't strictly necessary because the write event will be
330
+
// handled in #/firehose/ingestor.ts, but it ensures that future reads
331
+
// will be up-to-date after this method finishes.
333
+
.insertInto('status')
336
+
authorDid: agent.assertDid,
337
+
status: record.status,
338
+
createdAt: record.createdAt,
339
+
indexedAt: new Date().toISOString(),
347
-
const message = err instanceof Error ? err.message : 'Unknown error'
348
-
res.redirect(`/?error=${encodeURIComponent(message)}`)
345
+
'failed to update computed view; ignoring as it should be caught by the firehose',