Skip to content

Commit 16e729f

Browse files
committed
feat(logout): add logout
1 parent 81b12c9 commit 16e729f

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

cmd/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func StartServer(staticFS embed.FS) error {
5050
apisHandler.HandleFunc("POST /verify-otp", emailLoginApi.HandleEmailOTPVerification)
5151
apisHandler.HandleFunc("GET /login/google", googleLoginApi.HandleGoogleOAuthLogin)
5252
apisHandler.HandleFunc("/login/google/callback", googleLoginApi.HandleGoogleOAuthLoginCallback)
53+
apisHandler.HandleFunc("GET /logout", apis.HandleLogout)
5354
apisHandler.HandleFunc("GET /search-suggession", apis.HandleSearchSugessions)
5455
apisHandler.HandleFunc("GET /song/download/{youtube_video_id}", apis.HandleDownloadSong)
5556

handlers/apis/logout.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package apis
2+
3+
import (
4+
"dankmuzikk/config"
5+
"dankmuzikk/handlers"
6+
"net/http"
7+
)
8+
9+
func HandleLogout(w http.ResponseWriter, r *http.Request) {
10+
http.SetCookie(w, &http.Cookie{
11+
Name: handlers.SessionTokenKey,
12+
Value: "",
13+
Path: "/",
14+
Domain: config.Env().Hostname,
15+
MaxAge: -1,
16+
})
17+
http.Redirect(w, r, config.Env().Hostname, http.StatusTemporaryRedirect)
18+
}

views/pages/profile.templ

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ templ profile() {
1111
<pre>
1212
Profile:
1313
</pre>
14+
<a href="/api/logout">
15+
<button
16+
type="submit"
17+
class={ "bg-[#DE3333]", "text-white", "rounded-[50px]", "p-[10px]", "px-[60px]", "w-full" }
18+
>
19+
Logout
20+
</button>
21+
</a>
1422
</main>
1523
}

0 commit comments

Comments
 (0)