-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
234 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import { action, redirect } from "@solidjs/router"; | ||
import { $login, $resetPassword } from "~/lib/auth"; | ||
import { changeSession, resetSession } from "~/lib/auth/session"; | ||
import { components } from "~/lib/api/schema"; | ||
import { $authenticate, $resetPassword, $unauthenticate } from "~/lib/auth"; | ||
import { updateAuth } from "~/lib/auth/session"; | ||
|
||
export type LoginForm = { | ||
email: string; | ||
password: string; | ||
redirect: string | undefined; | ||
}; | ||
|
||
export const login = action(async (form: LoginForm) => { | ||
export const authenticate = action(async (form: LoginForm) => { | ||
"use server"; | ||
|
||
const { data, error, response } = await $login(form.email, form.password); | ||
const { data, error, response } = await $authenticate(form.email, form.password); | ||
|
||
if (data) { | ||
await changeSession({ token: data.access_token, expires_at: data.expires_at }); | ||
await updateAuth(data); | ||
} | ||
if (error) { | ||
return { error, code: response.status }; | ||
} | ||
|
||
throw redirect(form.redirect || "/settings"); | ||
throw redirect(form.redirect || "/"); | ||
}); | ||
|
||
export const resetPassword = action(async (body: components["schemas"]["UserPasswordReset"]) => { | ||
export const unauthenticate = action(async () => { | ||
"use server"; | ||
|
||
const data = await $resetPassword({ password: body.password, email: body.email, code: body.code}); | ||
await $unauthenticate(); | ||
|
||
if (data) { | ||
await changeSession({ token: data.access_token, expires_at: data.expires_at }); | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
throw redirect("/"); | ||
}); | ||
|
||
export const logout = action(async () => { | ||
export const resetPassword = action(async (body: components["schemas"]["UserPasswordReset"]) => { | ||
"use server"; | ||
|
||
await resetSession(); | ||
throw redirect("/"); | ||
const data = await $resetPassword(body); | ||
|
||
if (data) { | ||
await updateAuth(data); | ||
return true; | ||
} | ||
return false; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
import { getRequestEvent } from "solid-js/web"; | ||
import { updateSession, useSession } from "vinxi/http"; | ||
import { type Auth, type SessionData, SESSION_COOKIE_OPTIONS } from "~/lib/auth"; | ||
import { type SessionData, Auth, SESSION_COOKIE_OPTIONS } from "~/lib/auth"; | ||
|
||
export const getSession = async () => { | ||
return await useSession<SessionData>(SESSION_COOKIE_OPTIONS); | ||
}; | ||
|
||
export const changeSession = async (auth: Auth) => { | ||
export const changeSession = async (data: SessionData) => { | ||
"use server"; | ||
|
||
const event = getRequestEvent(); | ||
|
||
if (event) { | ||
await updateSession(event.nativeEvent, SESSION_COOKIE_OPTIONS, () => ({ auth: auth })); | ||
await updateSession(event.nativeEvent, SESSION_COOKIE_OPTIONS, () => data); | ||
} | ||
}; | ||
|
||
export const updateAuth = async (auth: Auth) => { | ||
"use server"; | ||
|
||
await changeSession({ | ||
auth: auth, | ||
}); | ||
}; | ||
|
||
export const resetSession = async () => { | ||
"use server"; | ||
|
||
await changeSession(undefined); | ||
await updateAuth(undefined); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.