Skip to content

Commit

Permalink
feat: add auth callback
Browse files Browse the repository at this point in the history
  • Loading branch information
unimu-cic committed Feb 4, 2024
1 parent e7ac1af commit 3c1fff6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {createRouteHandlerClient} from '@supabase/auth-helpers-nextjs'
import {cookies} from 'next/headers'
import {NextResponse} from 'next/server'

import type {NextRequest} from 'next/server'
import type {Database} from '../../../../types_db'

export async function GET(request: NextRequest) {
const requestUrl = new URL(request.url)
const code = requestUrl.searchParams.get('code')

if (code) {
const supabase = createRouteHandlerClient<Database>({cookies})
await supabase.auth.exchangeCodeForSession(code)
}

return NextResponse.redirect(`${requestUrl.origin}/dashboard`)
}
66 changes: 66 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {create} from 'zustand'
import {devtools} from 'zustand/middleware'

type Priority = 'High' | 'Medium' | 'Low'

export type Item = {
id: string,
user_id: string
title: string
description: string
startdate: Date
enddate: Date | null
priority: Priority | null
status: boolean
}

interface State {
list: Item[]
loading: boolean
empty: boolean
setLoading: (state: boolean) => void
addItem: (item: Item) => void
setList: (list: Item[] | null) => void
toggleItem: (item: Item) => void
updateItem: (id: string, item: Item) => void
}

export const useToDoState = create<State>()(devtools((set) => ({
list: [],
loading: false,
empty: false,
updateItem: (id: String, updates: Item) => set((state) => {
for (let i = 0; i < state.list.length; i++) {
if (state.list[i].id === id) {
state.list[i] = updates
break;
}
}
return {
list: [...state.list]
}
}),
addItem: (item: Item) => set((state) => ({
list: [...state.list, item],
empty: false
})),
toggleItem: (item: Item) => set((state) => {
for (let i = 0; i < state.list.length; i++) {
if (state.list[i].id === item.id) {
state.list[i].status = !item.status;
break;
}
}
return {
list: [...state.list]
}
}),
setList: (list: Item[] | null) => set(() => ({
list: list || [],
empty: list?.length === 0
})),
setLoading: (state) => set(() => ({
loading: state
})),
})))

0 comments on commit 3c1fff6

Please sign in to comment.